代码之家  ›  专栏  ›  技术社区  ›  Shashank Setty

仅使用xml的圆角ImageButton?

  •  0
  • Shashank Setty  · 技术社区  · 7 年前

    this is the type of button I'm trying to replicate

    然而,我似乎无法找到一种仅使用xml的方法。我试过自定义库,它们似乎并不完美。没有别的办法吗?我可以做什么来代替使用ImageButton?

    3 回复  |  直到 7 年前
        1
  •  0
  •   yadunath.narayanan    7 年前

    您可以使用具有卡角半径的cardview

    <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="4dp"/>
    

    并在cardview中添加imagebutton

        2
  •  0
  •   MetaSnarf    7 年前

    下面是一个xml代码。

    1.在可绘制文件夹(如button.xml)中创建一个xml文件,并粘贴以下标记:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true" >
            <shape android:shape="rectangle"  >
                <corners android:radius="3dp" />
                <stroke android:width="1dp" android:color="#5e7974" />
                <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92"  />            
            </shape>
        </item>
        <item android:state_focused="true">
            <shape android:shape="rectangle"  >
                <corners android:radius="3dip" />
                <stroke android:width="1dip" android:color="#5e7974" />
                <solid android:color="#58857e"/>       
            </shape>
        </item>  
        <item >
           <shape android:shape="rectangle"  >
                <corners android:radius="3dip" />
                <stroke android:width="1dip" android:color="#5e7974" />
                <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />            
           </shape>
        </item>
    </selector>
    

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textColor="#ffffff"
        android:background="@drawable/mybutton"
        android:text="Buttons" />
    

    归功于 this answer

        3
  •  0
  •   Rajat Mittal    7 年前

    在drawable中创建XML文件。

    <shape
          android:shape="rectangle"
            xmlns:android="http://schemas.android.com/apk/res/android">
    
        <corners
                android:radius="28dp"
        />
    
        <solid
            android:color="#00BADE"
    />
    </shape>
    

    然后在你的

        android:background="@drawable/buttonShape"
    
    推荐文章