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.blogchen.com" />
         </PreferenceScreen>
</com.blogchen.myview.MyPreferenceCategory>

 

 

 

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM