How to define a pixel unit (px, dp, etc.) of a View in Java?

I am trying to write unit test to verify the use of DIP. I can read the size value using editText.getTextSize (), but I cannot read the unit of text (in this case, it must ensure the use of "dp"). In test cases, someone changes the unit of text from dp to px or any other device.

<EditText
    android:id="@+id/someId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="48dp"/>

Thanks in advance!

+4
source share
2 answers

First, never run textSize on dp. They should always be used spso that people with vision problems can scale them as needed.

-, unit test ? ? , xml, ? Google, , . unit test - , . , ? , , dp vs px.

+3

, dp . , . :

lintOptions {
        warningsAsErrors true
        abortOnError true // Fail early.
}

@Gabe , Android. , , / xml.

- , , . , , .

- ,

+1

All Articles