2016-09-10 110 views
0

當我在佈局中放置按鈕時,它具有標準的灰色背景。但是我想讓它更像是在對話框中看到的那種按鈕,它是一個無背景按鈕(例如帶文本的白色按鈕)。Android中的按鈕樣式

像這樣

enter image description here

不是這個樣子......不是這個樣子......

enter image description here

+0

你到目前爲止嘗試了什麼?發佈您的代碼!當你運行它時發生了什麼?你預期會發生什麼? – Robert

回答

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"/> 
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