如何添加一个按钮,preferenceScreen [英] How to add a button to PreferenceScreen

查看:1488
本文介绍了如何添加一个按钮,preferenceScreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以添加一个按钮,preferences屏幕的底部,使他们的工作正确的滚动时?

Is there any way to add a button to the bottom of preferences screen and make them work correct when scrolling?

推荐答案

有用于定制preferences的外观另一种解决方案。

There is another solution for customizing the appearance of the preferences.

设计一个按钮或任何你想要添加到标准preferences一个正常的XML布局。在布局包含的ListView ,并给它的ID @android:ID /列表

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.

比方说,我们所说的布局文件 RES /布局/ main.xml中。它可能是这个样子:

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>

在你的 preferenceActivity ,这两行添加到您的的onCreate

In your PreferenceActivity, add these two lines to your onCreate:

addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.main);

的ListView 在你的布局将会再由preferences取代定义在 RES / XML / preferences通常的方式的.xml

The ListView in your layout will then be replaced by the preferences defined the usual way in res/xml/preferences.xml.

这篇关于如何添加一个按钮,preferenceScreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆