大家可能遇到,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"
</PreferenceScreen>
</com.blogchen.myview.MyPreferenceCategory>
}