我有一个自定义 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获取对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 GPS 获取用户的当前位置Get user#39;s current location using GPS(使用 GPS 获取用户的当前位置)
requestLocationUpdate() 抛出的 IllegalArgumentExceptionIllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 抛出的 IllegalArgumentException)
LocationManager 的 getLastKnownLocation 有多可靠,多久更How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新
如何检测位置提供者?GPS 或网络提供商How to detect Location Provider ? GPS or Network Provider(如何检测位置提供者?GPS 或网络提供商)
在应用启动期间获取当前位置Get current location during app launch(在应用启动期间获取当前位置)
locationManager.getLastKnownLocation() 返回 nulllocationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)