我想更改 android 首选项片段中的文本颜色。我目前正在使用自定义主题来更改复选框图像、背景、onClick 突出显示,除了文本颜色之外,一切都非常有效。我不想使用默认主题,我想拥有自己的主题,这样一切看起来都是我想要的,但只是更改文本颜色,有人可以帮忙吗?
样式.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="selectedTextStyle">
<item name="android:textSize">18sp</item>
</style>
<style name="buttonTextStyle">
<item name="android:textSize">20sp</item>
</style>
<style name="PreferencesTheme" >
<item name="android:windowBackground">@drawable/lists_background</item>
<item name="android:listViewStyle">@style/listViewPrefs</item>
<item name="android:checkboxStyle">@style/MyCheckbox</item>
</style>
<style name="MyTextAppearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/black</item>
</style>
<style name="listViewPrefs" parent="@android:Widget.ListView">
<item name="android:listSelector">@layout/list_selector_master</item>
<item name="android:textAppearance">@style/MyTextAppearance</item>
</style>
<style name="MyCheckbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/btn_check</item>
</style>
</resources>
显现:
<activity
android:name="com.package.SettingsActivity"
android:theme="@style/PreferencesTheme"
android:configChanges="keyboard|orientation" >
</activity>
活动:
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}
这是两个TextView
对象来自偏好.xml http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/frameworks/base/core/res/res/layout/preference.xml(布局为Preference
):
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
所以看起来你可以覆盖textAppearanceLarge
and textColorSecondary
在你的主题中实现颜色变化。这是一个例子:
<style name="AppTheme">
<item name="android:textAppearanceLarge">@style/MyTextAppearance</item>
<item name="android:checkboxStyle">@style/MyCheckBox</item>
</style>
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@android:drawable/btn_star</item>
</style>
<style name="MyTextAppearance" parent="@android:style/TextAppearance.Large">
<item name="android:textColor">#ff0000</item>
</style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)