当前位置: 移动技术网 > 移动技术>移动开发>Android > Android设置PreferenceCategory背景颜色的方法

Android设置PreferenceCategory背景颜色的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

本文实例讲述了android设置preferencecategory背景颜色的方法。分享给大家供大家参考。具体分析如下:

大家可能遇到,preferencecategory默认是黑色背景,如何我们更换了preferencescreen的背景,那么这种分隔栏看上去很丑,那么怎么更改背景呢?我们可以通过自定义view来实现。

代码如下:

public class mypreferencecategory extends preferencecategory {
 public mypreferencecategory(context context, attributeset attrs) {
  super(context, attrs);
 }
 @override
 protected void onbindview(view view) {
  super.onbindview(view);
  view.setbackgroundcolor(color.parsecolor("#b0000000"));
  if (view instanceof textview) {
   textview tv = (textview) view;
   tv.settextsize(16);
   tv.settextcolor(color.black);
  }
 }
}

在xml调用时(自定义用法。。。你懂的):

<com.blogchen.myview.mypreferencecategory android:title="其他" >
  <preferencescreen
   android:key="blog_"
   android:summary="作者博客地址"
   android:title="访问博客" >
   <intent
    android:action="android.intent.action.view"
    android:data="//www.jb51.net" />
  </preferencescreen>
</com.blogchen.myview.mypreferencecategory>

希望本文所述对大家的android程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网