問題描述
我有一個自定義 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
無論如何,當(dāng)我在我的應(yīng)用程序中使用 AlertDialog(非自定義)時,文本顏色會在不同的 android API 之間正確更改.
Anyway when in my app I use an AlertDialog (not custom) the text color changes properly between different android APIs.
所以,有沒有辦法通過 xml 獲取對話框使用的文本的顏色,以便我可以使用該值來設(shè)置上面的 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>
這篇關(guān)于Android獲取對話框文本顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!