Android中的按钮样式

时间:2016-09-10 22:04:01

标签: android button android-xml

当我在布局中放置一个按钮时,它具有标准的灰色背景。但是我想让它更像是你在Dialogs中看到的那种按钮,它是一个无背景的按钮(例如带文字的白色按钮)。

喜欢这个

enter image description here

不喜欢这个...不喜欢这个...

enter image description here

3 个答案:

答案 0 :(得分:1)

老问题,但我偶然发现它并得到答案(或者至少我认为),我真的不知道这是否是最好的方法,但它应该可以胜任。

<Button
    android:id="@+id/sign_in_button"
    style="@style/Widget.AppCompat.Button.Borderless.Colored"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

这里的诀窍是@style/Widget.AppCompat.Button.Borderless.Colored。另请参阅此答案,它解释了很多https://stackoverflow.com/a/36666660/1920068

答案 1 :(得分:0)

试试这个

android:background="@android:color/transparent"

答案 2 :(得分:0)

只需使用TextView,然后使用背景点击效果:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#23ac29"
        android:text="Signup"
        android:textSize="18sp"
        android:padding="8dp"
        android:background="?android:attr/selectableItemBackground"/>