Nic*_*ick 19 android android-preferences preferencescreen
我正在尝试创建一个只有一个关于,联系和合法选项的首选项屏幕,所有这些选项在单击时只显示单独页面中的文本模糊和图标,没有shared preferences
或任何内容.
我无法理解层次结构以显示文本.我希望这个流程是:settings -> about -> the about text
目前我有这个,它给了我类别和选项,但我不知道该怎么做才能显示新文本.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Info">
<Preference android:title="About"/>
</PreferenceCategory>
...
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
我不知道使用什么选项来将可点击进入textview.
Krz*_*iek 37
A.Grandt的解决方案在Preference Activity中提供了非常好的文本块模仿,但我会添加一个android:persistent="false"
属性,这样可以避免将不必要的"伪偏好"存储到SharedPreferences文件中,以用于应用程序的设置.
总结一下.在A.Adrand建议的模拟Preferences活动中的TextView将是:
<Preference
android:key="pref_static_field_key"
android:selectable="false"
android:persistent="false"
android:title="you can omit the title"
android:summary="Multi line description\ncan go here."/>
Run Code Online (Sandbox Code Playgroud)
虽然您可以使用\n
换行,但它不会调整首选项本身的大小,因此这些多行可能在一个单行首选项中不会完全可见.
A.G*_*ndt 24
我遇到了同样的问题,需要显示静态文本块.虽然在我的情况下,它已被列入首选项页面.
标签允许链接虽然不能解决对静态文本的需求.但是,Preference标签本身也是如此.您可以让它显示文本,通常的标题行,以及下面的文本摘要,两者都是可选的,然后使其无法选择.它会给出静态文本的错觉.
<Preference
android:key="pref_static_field_key"
android:selectable="false"
android:title="you can omit the title"
android:summary="Multi line description\ncan go here."/>
Run Code Online (Sandbox Code Playgroud)
Kor*_*lis 11
你不能在一个内部添加一个格式化的文本块PreferenceScreen
,这不是它的意思.但是,您可以在另一个活动中添加您的About文本(LinearLayout
带有一些格式化的TextView
s可能就足够了).通过在首选项中传递intent来调用它:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference
android:key="about"
android:title="About">
<intent android:action="your.package.path.to.Activity"/>
</Preference>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
我想添加一个文本块,但是以编程方式设置实际的文本内容.我的具体需求:在首选项屏幕顶部显示应用版本名称.
我按照A.Grandt和Krzysiek的方法完成了它,并在代码中设置了摘要.
dev_preferences.xml
:
<Preference
android:key="pref_app_version"
android:persistent="false"
android:selectable="false"
android:title="@string/app_name" />
Run Code Online (Sandbox Code Playgroud)
首选项片段(extends PreferenceFragment
):
private static final String KEY_APP_VERSION = "pref_app_version";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.dev_preferences);
findPreference(KEY_APP_VERSION).setSummary(BuildConfig.VERSION_NAME);
}
Run Code Online (Sandbox Code Playgroud)
我还最终通过在条目中设置使用自定义布局(如在此答案中).(不是强制性的,但通过这种方式,您可以轻松自定义首选项"标题"的外观.)android:layout="@layout/dev_preferences_header"
<Preference>
dev_preferences_header.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="@dimen/spacing_small">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17983 次 |
最近记录: |