gpt4 book ai didi

android - 在 PreferenceScreen 的首选项中添加一个 TextView

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:01 27 4
gpt4 key购买 nike

在此首选项屏幕中,用户取消设备与其帐户的链接。目前我只是将它作为取消链接设备,一旦用户点击它,就会发生取消链接。

但我想添加一段这样的文字:

Joe Foo 的设备 (joefoo@gmail.com) - 取消链接设备

我会这样做吗?我还需要从 settingsActivity 动态添加用户名。

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<Preference android:title="@string/pref_title_advanced_unlink" >
<TextView somehow must be in here
android:id="@id/user_name_and_email" />

<intent android:action="android.intent.action.VIEW"
android:targetPackage="com.example.tvrplayer"
android:targetClass="com.example.tvrplayer.UnlinkActivity"
android.setflags="FLAG_ACTIVITY_CLEAR_TOP"/>
</Preference>

</PreferenceScreen>

最佳答案

enter image description here

preferences.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:key="pref_title_advanced"
android:title="Advanced" >
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_title_advanced_link"
android:title="Link Device" />
</PreferenceCategory>
</PreferenceScreen>

PrefsActivity.java

private SharedPreferences mPreferences;
private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener;
private CheckBoxPreference mCheckBoxPref;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);

mCheckBoxPref = (CheckBoxPreference) getPreferenceScreen().findPreference(
"pref_title_advanced_link");
/*
* set initial summary as you desire. For example, userIdCurrent can be:
* "No Devices linked."
*/
mCheckBoxPref.setSummary(userIdCurrent);

mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs,
String key) {
if (key.equals("pref_title_advanced_link")) {
/*
* set post-click summary as you desire. For example,
* userIdPost can be:
* "Joe Foo's Device (joefoo@gmail.com)".
*/
mCheckBoxPref.setSummary(userIdPost);
}
}
};
mPreferences.registerOnSharedPreferenceChangeListener(mPrefListener);
}

关于android - 在 PreferenceScreen 的首选项中添加一个 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403682/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com