Android开对话文本颜色文本、颜色、Android

2023-09-03 22:46:47 作者:嘟,嘟,嘟…幸福占线

我有一个自定义对话框preference:

I have a custom DialogPreference:

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

这是my_diag_ preference.xml:

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>

现在的问题是,该TextView的文本颜色是错误的Andr​​oid的API 10。 文本颜色始终是黑色的。

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

截图: http://imgur.com/HDFOIJY

反正当我的应用程序我使用一个AlertDialog(不定制),文本颜色变化适当地不同的Andr​​oid API之间。

Anyway when in my app I use an AlertDialog (not custom) the text color changes properly between different android APIs.

所以, 有没有办法通过XML来获得使用的对话文本的颜色,这样我就可以使用该值来设置我的EditText的colorText以上?

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

感谢您的帮助

推荐答案

最后,我得到了一个解决方案。我找到了答案看这个文件: SDK /平台/ Android为10 /数据/ RES /价值/的themes.xml 的

Finally I got a solution. I found the answer looking at this file: sdk/platforms/android-10/data/res/values/themes.xml

我添加风格=机器人:ATTR / panelTextAppearance。到的EditText

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

所以上面的XML片段就变成了:

So the above piece of xml becomes:

<?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>