本文實例講述了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="http://www.49028c.com" /> </PreferenceScreen></com.blogchen.myview.MyPreferenceCategory>
希望本文所述對大家的Android程序設計有所幫助。
新聞熱點
疑難解答
圖片精選