Android获取对话框文本颜色

时间:2023-04-24
本文介绍了Android获取对话框文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个自定义 DialogPreference:

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>

问题是 Android API 10 中 TextView 的文本颜色错误.文本颜色始终为黑色.

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(非自定义)时,文本颜色会在不同的 android 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/platforms/android-10/data/res/values/themes.xml

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

我在 EditText 中添加了 style="?android:attr/panelTextAppearance".

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>

这篇关于Android获取对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何在不同类的非 UI 线程中创建对话框? 下一篇:如何在首选项中使用 QuietlyCoding 中的 NumberPicker?

相关文章