星空网 > 软件开发 > 操作系统

android开发Preference的使用

1  、Preference是androidSDK提供的一个基类从API1就开始有了,用于显示界面给用户。

2  、在使用Preference显示activity时,此activity需要继承Preferenceactivity,  在oncreate方法里面实现addPreferencesFromResource(R.3 、布局文件有三种标签
PreferenceScreen  根节点
PreferenceCategory  分类结点
Preference  子节点
<??><PreferenceScreen ="http://schemas.android.com/apk/res/android" >  <PreferenceCategory android:title="@string/general" >    <Preference android:title="@string/properties" />    <Preference android:title="@string/attach" />    <Preference android:title="@string/left_and_right" />    <Preference android:title="@string/changing_fragments" />    <Preference android:title="@string/responsive_ui" />    <Preference android:title="@string/viewpager" />  </PreferenceCategory>  <PreferenceCategory android:title="@string/title_bar" >    <Preference android:title="@string/title_bar_slide" />    <Preference android:title="@string/title_bar_content" />  </PreferenceCategory>  <PreferenceCategory android:title="@string/animations" >    <Preference android:title="@string/anim_zoom" />    <Preference android:title="@string/anim_scale" />    <Preference android:title="@string/anim_slide" />  </PreferenceCategory></PreferenceScreen>

4 、重写 onPreferenceTreeClick方法实现监听

  @Override  public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pref) {    Class<?> cls = null;    String title = pref.getTitle().toString();    if (title.equals(getString(R.string.properties))) {      cls = PropertiesActivity.class;      } else if (title.equals(getString(R.string.attach))) {      cls = AttachExample.class;    } else if (title.equals(getString(R.string.changing_fragments))) {      cls = FragmentChangeActivity.class;    } else if (title.equals(getString(R.string.left_and_right))) {      cls = LeftAndRightActivity.class;    } else if (title.equals(getString(R.string.responsive_ui))) {      cls = ResponsiveUIActivity.class;    } else if (title.equals(getString(R.string.viewpager))) {      cls = ViewPagerActivity.class;    } else if (title.equals(getString(R.string.title_bar_slide))) {      cls = SlidingTitleBar.class;    } else if (title.equals(getString(R.string.title_bar_content))) {      cls = SlidingContent.class;    } else if (title.equals(getString(R.string.anim_zoom))) {      cls = CustomZoomAnimation.class;    } else if (title.equals(getString(R.string.anim_scale))) {      cls = CustomScaleAnimation.class;    } else if (title.equals(getString(R.string.anim_slide))) {      cls = CustomSlideAnimation.class;    }    Intent intent = new Intent(this, cls);    startActivity(intent);    return true;  }

 


 



原标题:android开发Preference的使用

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

亚马逊运营的必经之路!:https://www.ikjzd.com/articles/124176
Facebook广告重要更新:9月开始将取消目标费用出价策略!:https://www.ikjzd.com/articles/124177
Shopee无货源商家店铺数据分析需要掌握的几点数据:https://www.ikjzd.com/articles/124178
2020 年Prime Day会员日或不再举行?卖家何去何从?:https://www.ikjzd.com/articles/124198
lazada的入驻流程,入驻条件及热卖品类目分享:https://www.ikjzd.com/articles/124201
新手卖家如何快速上道亚马逊?:https://www.ikjzd.com/articles/124204
2022世界杯门票如何买?:https://www.vstour.cn/a/363182.html
沈阳到本溪的距离有多远?(详细路线及交通方式):https://www.vstour.cn/a/363183.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流