Java 如何在 Android 的 PreferenceScreen 中使用 textview?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18333409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use textview in Android's PreferenceScreen?
提问by Badr Hari
I would like to use textview in PreferenceScreen, it's a longer text that explains some specific setting. If I use summary or title attribute on some versions it gets formatted weirdly, doesn't display correctly etc. (The text is rather long).
我想在 PreferenceScreen 中使用 textview,它是一个解释某些特定设置的较长文本。如果我在某些版本上使用 summary 或 title 属性,它的格式会很奇怪,无法正确显示等(文本很长)。
Therefor I find it would be the best to use textview, is it possible to create custom settings element?
因此我发现最好使用 textview,是否可以创建自定义设置元素?
采纳答案by Ber?ák
You can assign layout resource for your preference in your xml file, using tag android:layout="@layout/your_pref_layout"
.
您可以使用 tag 在 xml 文件中根据您的喜好分配布局资源android:layout="@layout/your_pref_layout"
。
Don't forget to use proper ids in your layout (android:id="@+android:id/title", android:id="@+android:id/summary") to assign views to be used as title/summary views.
不要忘记在布局中使用正确的 id(android:id="@+android:id/title", android:id="@+android:id/summary")来分配要用作标题/摘要的视图意见。
For more info see for example this: Creating a custom layout for preferences
有关更多信息,请参见例如:为首选项创建自定义布局
回答by Rajnish Mishra
Yes You can create a layout and use that layout file to inflate as your preference screen you can see a example here.
是的,您可以创建一个布局并使用该布局文件将其扩展为您的首选项屏幕,您可以在此处查看示例。
回答by zackygaurav
Use this:
用这个:
<Preference
android:selectable="false"
android:enabled="true"
android:key="example_key"
android:title="example_title"
android:summary="anything_you_want" />
The attributes selectablewill decide the click action of the Preference.
可选的属性将决定 Preference 的点击动作。