为 Fragment 的Preference 添加自定义的布局
来源:互联网 发布:淘宝0元购平台 编辑:程序博客网 时间:2024/04/30 15:27
添加 Preference 文件:
@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);addPreferencesFromResource(R.xml.system_cloud_sync_settings);}
添加自定义布局:
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {return inflater.inflate(R.layout.fragment_cloud_sync_settings, null);}
布局文件:fragment_cloud_sync_settings.xml
<?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:paddingTop="10dip" android:paddingLeft="30dip" android:orientation="vertical" > <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cloud_sync" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/tv_summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cloud_sync_title_summary" /> <View android:layout_width="fill_parent" android:layout_height="2dp" android:background="?android:attr/listDivider" /> <!-- 这个根ListView必不可少,否则 Preference 无法加载,报错 --> <include layout="@layout/settings_root_layout" /></LinearLayout>
其中settings_root_layout.xml 这个文件必不可少否则Preference无法加载,而且注意id的命名,为系统的id
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadingEdgeLength="0dip" android:scrollbarStyle="outsideOverlay" android:scrollbars="none" />
- 为 Fragment 的Preference 添加自定义的布局
- preference自定义布局findViewById无法使用的问题
- 为我们的UITableViewFooterHeaderView添加自定义View的布局
- Fragment的布局中自定义Layout的onSizeChanged添加组件失败的问题
- 自定义 Preference Header 布局
- android 自定义preference的属性
- Android 中Preference作为布局的应用
- ListView添加头布局的自定义控件
- 为Recycle添加头尾布局的BaseAdapter
- 编写自定义的 Android Preference 组件
- 编写自定义的 Android Preference 组件
- 编写自定义的 Android Preference 组件
- 自定义preference onBindView易犯的错误
- Android中自定义Preference的使用
- 自定义Preference时遇到的问题
- 关于Fragment的新认识—动态添加布局
- Fragment与自定义布局实现类似tab的效果
- Fragment与自定义布局实现类似tab的效果
- DB_WRITER_PROCESSES与LOG_ARCHIVE_MAX_PROCESSES
- Android桌面悬浮窗效果实现,仿360手机卫士悬浮窗效果
- treeview 绑定 datatable 或 dataset 添加节点
- NCL命令行快捷键
- Xilinx FPGA用户约束文件
- 为 Fragment 的Preference 添加自定义的布局
- tomcat Per Gem内存不足
- POJ 2516
- 【检测tor程序占用9050端口的办法和解决问题】
- IOS触屏应用开发
- 打印机驱动安装打印机端口监视
- 车牌定位问题
- 错误 155 程序集“Microsoft.Office.Interop.Excel, Version=12.0.0.0
- Android系统联系人全特效实现(上),分组导航和挤压动画