亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Androidx 中更改偏好的文本顏色

如何在 Androidx 中更改偏好的文本顏色

忽然笑 2023-06-21 14:50:20
我想在 Preference.xml 文件中更改 Preference 的文本顏色XML代碼<?xml version="1.0" encoding="utf-8"?><androidx.preference.PreferenceScreen    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto">    <androidx.preference.Preference        android:key="pref_entries"        android:title="@string/settings_entries"        android:summary="0"        android:enabled="true"        app:iconSpaceReserved="false" /></androidx.preference.PreferenceScreen>我嘗試在 xml 文件中添加 textcolor 但它不起作用Java代碼 prefEntries = pm.findPreference(Const.PREF_ENTRIES);如何更改首選文本顏色
查看完整描述

1 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

使用此自定義 PreferenceCategory 類:


public class MyPreferenceCategory extends PreferenceCategory {

    public MyPreferenceCategory(Context context) {

        super(context);

    }


    public MyPreferenceCategory(Context context, AttributeSet attrs) {

        super(context, attrs);

    }


    public MyPreferenceCategory(Context context, AttributeSet attrs,

            int defStyle) {

        super(context, attrs, defStyle);

    }


    @Override

    protected void onBindView(View view) {

        super.onBindView(view);

        TextView titleView = (TextView) view.findViewById(android.R.id.title);

        titleView.setTextColor(Color.RED);

    }

}

并將其添加到您的 Pref.xml 文件中:


<ali.UI.Customize.MyPreferenceCategory android:title="@string/pref_server" />

方法 2:一種簡單的方法是在此處設置自定義布局preferenceCategory:


<PreferenceCategory

    android:layout="@layout/preferences_category"

    android:title="Privacy">

一種簡單的方法是在此處為 preferenceCategory 設置自定義布局:


<PreferenceCategory

    android:layout="@layout/preferences_category"

    android:title="Privacy" >

然后在布局文件中設置代碼preferences_category:


<TextView

    android:id="@android:id/title"

    android:textColor="@color/deep_orange_500"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:textSize="16sp"

    android:textStyle="bold"

    android:textAllCaps="true"/>


查看完整回答
反對 回復 2023-06-21
  • 1 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號