Border color on Android button

前端 未结 6 699
猫巷女王i
猫巷女王i 2021-02-05 04:47

I have a button created and have set the background color and text color as can be seen below. My question is: how do I set the buttons border color? I want to set the border co

相关标签:
6条回答
  • 2021-02-05 05:27

    try Material button

    Set app:strokeWidth, app:strokeColor as per your need

    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:strokeWidth="0.6dp"
        app:cornerRadius="2dp"
        android:text="Reassign"
        android:textColor="@color/colorAccent"
        app:strokeColor="@color/colorAccent"
    
        />
    

    Note : you need to add dependency for material widgets

    //Material Components for Android
    implementation 'com.google.android.material:material:1.0.0'
    
    0 讨论(0)
  • 2021-02-05 05:31

    Use the <stroke> element. Add this xml file in res/drawable folder as button_border.xml:

     <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#FFFFFF" 
           android:endColor="#00FF00"
           android:angle="270" />
        <corners android:radius="3dp" />
        <stroke android:width="5px" android:color="#ffffff" />
     </shape>
    

    then call this by

    <Button
       android:id="@+id/button1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_margin="10dp"
       android:background="@drawable/button_border"
       android:text="Button" 
    />
    
    0 讨论(0)
  • 2021-02-05 05:32

    Try this

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    
    <corners android:radius="1dp" />
    
    <stroke
        android:width="2px"
        android:color="#ffffff" />
    
    </shape>
    
    0 讨论(0)
  • 2021-02-05 05:38

    If you would like a transparent background for your button, then use Shivang Trivedi's answer but remove the "gradient" section like so:

    <?xml version="1.0" encoding="utf-8"?>   <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:radius="3dp" />
        <stroke android:width="5px" android:color="#ffffff" />  </shape>
    
    0 讨论(0)
  • 2021-02-05 05:40

    You can use this Online Button generator to Customize your button http://angrytools.com/android/button/

    0 讨论(0)
  • 2021-02-05 05:41

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    
    <gradient
        android:angle="270"
        android:endColor="#E8f2fe"
        android:startColor="#E8f2fe" />
    
    <corners android:radius="3dp" />
    
    <stroke
        android:width="2px"
        android:color="#486e9d" />
    
    0 讨论(0)
提交回复
热议问题