日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在PreferenceScreen加入自定义布局

發(fā)布時間:2023/12/14 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在PreferenceScreen加入自定义布局 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

想在PreferenceScreen頁面加入一個自定義的布局,這里以加入一個button為例,記錄一下

加入一個自定義布局有兩種方式:

  • 使用Preference的android:layout屬性
  • <Preferenceandroid:key="preference_key_you_want"android:title="preference_title_you_want"android:summary="preference_summary_you_want"android:layout="@layout/your_custom_layout"/>

    然后在your_custom_layou.xml文件中定一個button,你懂的!

    在android:layout屬性指定你自定義的layout,注意preference的布局是定義在xml目錄下的

    2. 定義一個layout布局文件且布局要包含ListView android:id="@android:id/list"

    1)在layout目錄下單獨寫一個布局layout文件,定義你想要的布局,注意一定要包含ListView且id為@android:id/list,為要展示的perference占位

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_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="match_parent"android:layout_height="wrap_content" /> </LinearLayout>

    2)然后在xml目錄下定義preference文件,preference文件不需要考慮自定義的布局

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"><Preferenceandroid:key="preference_key_you_want"android:title="preference_title_you_want"android:summary="preference_summary_you_want"android:layout="@layout/your_custom_layout"/> </PreferenceScreen>

    3)在PreferenceActivity中加入兩行代碼:

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

    兩種方式在使用上的區(qū)別之一:
    第二種方式可以不受perference的style影響

    總結(jié)

    以上是生活随笔為你收集整理的在PreferenceScreen加入自定义布局的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。