如何在布局中包含偏好
问题描述:
我可以在布局中包含偏好,例如我们如何使用<include layout=""/>
标签将布局包含在另一个布局中。如何在布局中包含偏好
我的布局代码是这样
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
<include layout="@layout/settings"/>
<!-- <include layout="@xml/set_variables"/> -->
</LinearLayout>
在上面的布局我试图包括偏好@xml/set_variables
,但如果我取消<include layout="@xml/set_variables"/>
我的应用程序会崩溃。请任何人建议有没有办法在布局中包含偏好或只是我应该忘记这一点。
答
我通过this Link了,发现解决方案 在PreferenceActivit
onCreate
Ÿ我已经加入
setContentView(R.layout.settings);
addPreferencesFromResource(R.xml.set_variables);
和settings
布局添加ListView
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
它满足了我的要求