Android获取对话框文本颜色

Android get Dialog text color(Android获取对话框文本颜色)
本文介绍了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获取对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)