首页 > 代码库 > How to add a button to PreferenceScreen
How to add a button to PreferenceScreen
There is another solution for customizing the appearance of the preferences.
Design a normal XML layout with buttons or whatever you want to add to the standard preferences. Include a ListView
in your layout and give it the ID @android:id/list
.
Let‘s say we call the layout file res/layout/main.xml
. It could look something like this:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:text="This is a button on top of all preferences." android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /></LinearLayout>
In your PreferenceActivity
, add these two lines to your onCreate
:
addPreferencesFromResource(R.xml.preferences);setContentView(R.layout.main);
The ListView
in your layout will then be replaced by the preferences defined the usual way in res/xml/preferences.xml
.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。