【发布时间】:2017-12-31 20:52:48
【问题描述】:
所以目前我有一个 PreferenceFragment 有几个偏好,如下所示:
<PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="menu"
android:key="menu">
<PreferenceScreen
android:title="pref1"
android:key="pref1" />
<PreferenceScreen
android:title="pref2"
android:key="pref2" />
</PreferenceCategory>
</PreferenceScreen>
如果我想将“pref2”的颜色更改为红色,我该怎么做?我看过几个不同的解决方案。其中之一是创建自己的布局。所以我尝试了:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:textColor="#FF0000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="pref2"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
它不起作用,因为边距关闭,高度被包裹而不是匹配父项,并且尺寸似乎也关闭了。有什么建议吗?
【问题讨论】:
标签: android layout textview preferenceactivity preferencefragment