软件编程
位置:首页>> 软件编程>> Android编程>> Android设置PreferenceCategory背景颜色的方法

Android设置PreferenceCategory背景颜色的方法

作者:3H  发布时间:2021-09-24 10:13:29 

标签:Android,背景

本文实例讲述了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="https://www.jb51.net" />
 </PreferenceScreen>
</com.blogchen.myview.MyPreferenceCategory>

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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com