2016-07-15 21 views
6

में लागू नहीं हो रहा है, मैं कस्टम चेकबॉक्स और रेडियो बटन विकसित कर रहा हूं लेकिन शैली पूर्व लॉलीपॉप डिवाइसों (इसके बजाय काले रंग दिखा रहा है) दोनों के लिए आवेदन नहीं कर रही है। मैं इस तरह से कोडित हैस्टाइल कस्टम चेकबॉक्स और रेडियोधटन

एक्सएमएल:

<com.kaho.myapp.CustomCheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="CheckBoxText" 
    android:textColor="@color/colorPrimary" 
    android:theme="@style/SampleTheme"/> 

कस्टम चेकबॉक्स: ठीक से स्थापित करने में

public class CustomCheckBox extends CheckBox { 
    public CustomCheckBox(Context context) { 
     super(context); 
    } 

    public CustomCheckBox(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     setFont(context, attrs) ; 
    } 

    public CustomCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     setFont(context,attrs) ; 
    } 

    public CustomCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
     setFont(context, attrs) ; 
    } 

    private void setFont(Context context, AttributeSet attrs) { 
     if (attrs != null) { 
      /* Set the font */ 
     } 
    } 
} 

फ़ॉन्ट। शैली:

<style name="SampleTheme" parent="Theme.AppCompat.Light"> 
    <item name="colorAccent">#08c283</item> 
    <item name="android:textColorSecondary">#969696</item> 
</style> 

उत्तर

3

क्योंकि पूर्व लॉलीपॉप उपकरणों की जरूरत नहीं है आप इस समस्या है डिफ़ॉल्ट रूप से colorAccent सेट करने की संभावना। इस तरह के व्यवहार को प्राप्त करने के लिए संबंधित दृश्य दृश्य से अपना विचार बढ़ाएं। इस तरह कुछ होगा:

public class CustomCheckBox extends AppCompatCheckBox 
public class CustomRadioButton extends AppCompatRadioButton 

इस तरह, आपके विचारों में प्री लॉलीपॉप डिवाइस पर सामग्री डिज़ाइन शैली होगी।

+0

धन्यवाद यह काम कर रहा है ... – Nikesh

0

कस्टम चेक बॉक्स पर एक नज़र यह सब संस्करण पूर्व/पोस्ट लॉलीपॉप के लिए अच्छा काम करता है ले लो।

CustomCheckBox.java:

public class CustomCheckBox extends CheckedTextView { 
    private Drawable btnDrawable; 

    public CustomCheckBox(Context context) { 
     this(context, null); 
    } 

    public CustomCheckBox(Context context, AttributeSet attrs) { 
     this(context, attrs, 0); 
    } 

    public CustomCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     colorAccordingToTheme(); 
    } 

    @Override 
    public void setCheckMarkDrawable(Drawable d) { 
     super.setCheckMarkDrawable(d); 
     btnDrawable = d; 
    } 

    @Override 
    public void toggle() { 
     super.toggle(); 
     colorAccordingToTheme(); 
    } 

    @Override 
    public void setChecked(boolean checked) { 
     super.setChecked(checked); 
     colorAccordingToTheme(); 
    } 

    private void colorAccordingToTheme() { 
     if (btnDrawable != null) { 
      btnDrawable.setColorFilter(yourColor, PorterDuff.Mode.SRC_IN); 
     } 
    } 
} 

XML लेआउट में:

<?xml version="1.0" encoding="utf-8"?> 
<com.yourpaackcge.CustomCheckBox xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/cb" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:checkMark="@drawable/selector_check_box" 
    android:gravity="center|left" 
    android:paddingRight="24dp" 
    android:paddingLeft="24dp" 
    android:background="@drawable/ripple"/> 

मेरे चयनकर्ता:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/ic_check_box_on" android:state_pressed="true"/> 

    <item android:drawable="@drawable/ic_check_box_on" android:state_checked="true"/> 

    <item android:drawable="@drawable/ic_check_box_off"/> 
</selector> 
संबंधित मुद्दे