2016-07-12 32 views
6

एंड्रॉइड बटन में रंग जोड़ने के बाद, यह इसके तरंग प्रभाव को खो देता है जिससे उपयोगकर्ता को लगता है कि एक उत्तरदायी क्लिक है। मैं यह कैसे तय करुं? मैंने कई समाधानों के माध्यम से खोज की है लेकिन मुझे एक निश्चित व्यक्ति नहीं मिला जो संदिग्ध नहीं था।एंड्रॉइड, बटन का पृष्ठभूमि रंग सेट करना लहर प्रभाव को खो देता है

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       tools:context=".ClockInOutFragment"> 


    <AnalogClock 
     android:id="@+id/clock" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/date_and_time"/> 


    <RelativeLayout 
     android:id="@+id/date_and_time" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp"> 

     <TextView 
      android:id="@+id/time_digits" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="12:10" 
      android:textSize="45sp"/> 

     <TextView 
      android:id="@+id/am_pm" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/time_digits" 
      android:layout_toRightOf="@+id/time_digits" 
      android:paddingLeft="3dp" 
      android:text="PM" 
      android:textSize="20sp"/> 

     <TextView 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/time_digits" 
      android:text="Mon, July 11" 
      android:textSize="22sp"/> 
    </RelativeLayout> 

    <!--Clock in and out buttons--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/textView3" 
      android:layout_width="0dp" 
      android:layout_height="56dp" 
      android:layout_weight="1" 
      android:background="#4CAF50" 
      android:gravity="center" 
      android:text="Clock In" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#FFFFFF"/> 

     <!--Divider between the clock in and out button--> 
     <View 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:background="#B6B6B6"/> 

     <Button 
      android:id="@+id/textView4" 
      android:layout_width="0dp" 
      android:layout_height="56dp" 
      android:layout_weight="1" 
      android:background="#FF5252" 
      android:gravity="center" 
      android:text="Clock Out" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#FFFFFF"/> 
    </LinearLayout> 


</RelativeLayout> 

उत्तर

9

आप एक additionnal लहर drawable के साथ असर & पृष्ठभूमि रंग जोड़ सकते हैं:

अपने लेआउट:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/button_connect" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dip" 
     android:fontFamily="sans-serif" 
     android:text="Connect" 
     android:background="@drawable/ripple" 
     android:textColor="#FFFFFF" 
     android:textSize="18sp" /> 

</LinearLayout> 

ripple.xml (इस जहां अलावा पृष्ठभूमि रंग जोड़ सकते हैं लहर प्रभाव के लिए):

<?xml version="1.0" encoding="utf-8"?> 
<!-- in drawable folder--> 
<ripple 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="?android:colorControlHighlight"> 

    <item android:id="@android:id/mask"> 
     <shape android:shape="rectangle"> 
      <solid android:color="?android:colorAccent" /> 
     </shape> 
    </item> 

    <item> 
     <shape android:shape="rectangle"> 
      <!-- put your background color here--> 
      <solid android:color="@color/default_color" /> 
     </shape> 
    </item> 

</ripple> 
+0

कैसे एंड्रॉइड अंतर करता है कि कौन सा मुखौटा है और कौन सा डिफ़ॉल्ट रंग है? –

7

मत बदलें बटन की पृष्ठभूमि। विषय बदलें।

<style name="ButtonGray"> 
    <item name="colorButtonNormal">@color/gray</item> 
</style> 

और अपने xml फ़ाइल

<Button 
    android:id="@+id/accept_button" 
    android:layout_height="wrap_content" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:text="@string/button_accept_group" 
    android:theme="@style/ButtonGray"/> 

या फिर आप अपने मुख्य अनुप्रयोग विषय

<style name="AppTheme" 
      parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorButtonNormal">@color/primary_color</item> 
</style> 

में जोड़ सकते हैं और परिवर्तन बटन पृष्ठभूमि की जरूरत नहीं है में।

यदि आप पूरी तरह से कस्टम पृष्ठभूमि चाहते हैं तो आपको अपना चयनकर्ता बनाना होगा। और आप वहां लहर प्रभाव डाल सकते हैं।

0

बस का उपयोग करें:

android:backgroundTint="#4CAF50" 

बजाय:

android:background="#4CAF50" 

मत भूलना कर यह करने के लिए है की अपनी Buttonandroid.support.v7.widget.AppCompatButton

+0

मैंने बदल दिया लेकिन यह काम नहीं कर रहा है –

1

एक करने के लिए बहुत ही सरल और सीधे आगे रास्ता बदलने के लिए अपने बटन की विशेषता ?attr/selectableItemBackground से android:foreground सेट करें। निम्नलिखित xml पूरी तरह से मान्य है और

<Button 
    android:id="@+id/btn" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" 
    android:foreground="?attr/selectableItemBackground"/> 
संबंधित मुद्दे