本文实例讲述了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程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
Codeforces C. A Cookie for You (模拟 / 分类 / 贪心) (Round #654 Div.2)
DialogFragment弹窗(带黑色透明背景和不带黑色透明背景)
android 常用布局文件(LinearLayout,RelativeLayout,FrameLayout,ConstraintLayout,TableLayout)
网友评论