2017-03-09 6 views
11

पर घुमावदार कोनों सामग्री सामग्री पर सुझाए गए बटन शैली बनाने के लिए this जैसे प्रश्नों की युक्तियों का पालन कर रहा हूं।सामग्री बटन

Button

हालांकि, मैं कोने की त्रिज्या बदलने की जरूरत है और न Widget.AppCompat.Button.Colored शैली विरासत में और त्रिज्या पैरामीटर द्वारा ऐसा करने में सक्षम है।

मेरे पास समान शैली कैसे हो सकती है लेकिन गोलाकार कोनों के साथ?

उत्तर

14

आपको उस शैली का उत्तराधिकारी होना चाहिए।

अपने styles.xml में जोड़ें:

<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored"> 
     <item name="android:background">@drawable/rounded_shape</item> 
</style> 

जोड़े फ़ाइल drawable/rounded_shape.xml:

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <solid 
     android:color="@color/colorAccent" > 
    </solid> 

    <corners 
     android:radius="11dp" > 
    </corners> 

</shape> 

और अंत में अपने लेआउट में:

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test Text" 
     style="@style/AppTheme.RoundedCornerMaterialButton"/> 

संपादित करें: अद्यतन जवाब हार्डकोडेड की बजाय थीम के रंग का उपयोग करने के लिए।

+2

हालांकि, इस बटन से असर को हटा। अनुकूलित बटन पर लहर प्रभाव कैसे प्राप्त करें? – ssudaraka

+0

@ सुपुनसुद्रका http://stackoverflow.com/a/24530169/401025 –

+0

@ लोस्टिनबीलेफेल्ड धन्यवाद, मैं इसे आजमाउंगा। – ssudaraka

0

इसके अलावा एक और आसान तरीका cardView चारों ओर लपेट, wrap_content को layout_width और cardView की layout_height सेट करना न भूलें है, यह भी सभी आवश्यक मार्जिन बटन की आवश्यकता होगी cardView

<android.support.v7.widget.CardView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:cardCornerRadius="8dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginBottom="40dp" 
      app:elevation="10dp"> 

      <android.support.v7.widget.AppCompatButton 
       android:id="@+id/login_twitter" 
       android:tag="login_twitter" 
       android:layout_width="300dp" 
       android:layout_height="60dp" 
       android:paddingLeft="10dp" 
      android:foreground="?attr/selectableItemBackgroundBorderless" 
       android:textColor="@color/blue_grey_ligthen_5" 
       android:drawableLeft="@drawable/twitter" 
       android:background="@color/twitter" 
       android:text="@string/login_with_twitter" /> 
     </android.support.v7.widget.CardView> 
0

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

चयनकर्ता टैग के दूसरे आइटम में विपरीत व्यवहार है। आप चयनकर्ता (बटन व्यवहार) के रूप में के रूप में ज्यादा जोड़ सकते हैं बटन एंड्रॉयड की पृष्ठभूमि के रूप में इस drawable एक्सएमएल जोड़ें: "@ drawable/इस xml" पृष्ठभूमि =

<?xml version="1.0" encoding="utf-8"?> 
<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="#ffffff"> <!-- this is the ripple color(first touch color changes into this color) --> 
    <item> 
     <selector> 
      <item android:state_enabled="true"> 
       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <!-- default button color --> 

        <solid android:color="@color/colorPrimary"></solid> 

        <corners android:radius="151dp"></corners> 

       </shape> 
      </item> 
      <item> 
       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <!-- button disabled color opposite behaviour --> 
        <solid android:color="#e9d204"></solid> 

        <corners android:radius="151dp"></corners> 

       </shape> 
      </item> 
     </selector> 
    </item> 
    <item> 
     <selector> 
      <item android:state_pressed="true"> 
       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <!-- button first touch of your finger color --> 
        <solid android:color="#1989fa"></solid> 

        <corners android:radius="151dp"></corners> 

       </shape> 
      </item> 
     </selector> 
    </item> 
    <item> 
     <selector> 
      <item android:state_hovered="true"> 
       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <!-- hovered with a note pencil --> 
        <solid android:color="#4affffff"></solid> 

        <corners android:radius="151dp"></corners> 

       </shape> 
      </item> 
     </selector> 
    </item> 

</ripple> 
संबंधित मुद्दे