Android の設定フラグメントでテキストの色を変更したいです。現在、チェックボックスの画像、背景、クリック時の強調表示を変更するためにカスタム テーマを使用していますが、テキストの色以外はすべてうまく機能しています。デフォルトのテーマは使用したくないので、独自のテーマを使用して、テキストの色だけを変更して、すべてを希望どおりに表示したいのですが、誰か助けていただけませんか。
スタイル.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);
}
}
}
ベストアンサー1
ここに2つのTextView
オブジェクトがあります設定.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
て色を変更できるようです。次に例を示します。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>