Android Dialog Text Color

I have a custom DialogPreference function:

public class MyDiagPreference extends DialogPreference { public MyDiagPreference(Context context, AttributeSet attrs) { super(context, attrs); this.setDialogLayoutResource(R.layout.my_diag_preference); } } 

This is my_diag_preference.xml:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="8dp" android:orientation="vertical" > <TextView android:id="@+id/testTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Test TextView" /> </LinearLayout> 

The problem is that the text color of the TextView is incorrect in Android API 10. The color of the text is always black.

screenshot: http://imgur.com/HDFOIJY

In any case, when I use AlertDialog (non-standard) in my application, the text color changes correctly between the various Android APIs.

So, is there a way to get the color of the text used by the dialog box through xml so that I can use this value to set the colorText of my EditText above?

thanks for the help

0
source share
2 answers

Finally, I got a solution. I found the answer by looking at this file: SDK / platform / Android-10 / data / RES / value / themes.xml

I added style="?android:attr/panelTextAppearance" to EditText.

So the above xml snippet will look like this:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="8dp" android:orientation="vertical" > <TextView android:id="@+id/testTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Test TextView" style="?android:attr/panelTextAppearance" /> </LinearLayout> 
+1
source

Set the text color in the TextView and you will get the text color according to your requirement.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="8dp" android:orientation="vertical" > <TextView android:id="@+id/testTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#000000" android:text="Test TextView" /> </LinearLayout> 
0
source

Source: https://habr.com/ru/post/1204371/


All Articles