2012-03-14 135 views
20

我討厭成爲第三個問這個問題的人,但之前的twoaskings似乎還沒有完全回答。 Android設計準則詳述borderless buttons,但不是如何製作它們。在前面的答案之一,有一個sugestion使用方法:Android無邊界按鈕

style="@android:style/Widget.Holo.Button.Borderless"

這非常適用於一個全息主題,但我用了很多Holo.Light,以及和

style="@android:style/Widget.Holo.Light.Button.Borderless"

似乎並不存在。有沒有辦法在Holo.Light中爲無邊框按鈕應用樣式,或者更好,只需應用無邊框標籤而不指定它屬於哪個主題,以便應用程序可以在運行時選擇適當的樣式?

Holo.ButtonBar似乎符合我正在尋找的法案,除非它沒有提供任何用戶反饋,它已被按下。

另外,在文檔中是否有一個地方列出了可應用的樣式以及對它們的描述?不管我有多少谷歌,並通過文檔搜索,我找不到任何東西。如果我右鍵單擊並編輯樣式,則只有一個非描述性列表。

任何幫助,將不勝感激。

編輯:從javram得到了一個完美的答案,我想爲任何有興趣添加谷歌已採用的部分邊框的人添加一些XML。

佛拉水平分隔,這個偉大的工程

<View 
    android:id="@+id/horizontal_divider_login" 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:background="@color/holo_blue" /> 

這對於一個垂直:

<View 
    android:id="@+id/vertical_divider" 
    android:layout_width="1dip" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="8dp" 
    android:layout_marginTop="8dp" 
    android:background="@color/holo_blue" /> 

回答

21

檢查出我的回答here。簡而言之正確的解決方法是使用以下命令:

android:background="?android:attr/selectableItemBackground" 
+6

當您使用Android 2.2,2.3.x時,它不起作用:( – Xdg 2012-10-07 05:50:06

+0

@Xdg在使用HolloEveywhere時會起作用:https://github.com/Prototik/HoloEverywhere/ – 2013-05-19 06:19:15

+5

如果您使用AppCompat庫,然後刪除「android:」前綴,它將工作: android:background =「?attr/selectableItemBackground」 – 2014-05-29 10:21:48

8

此代碼將刪除所有背景的按鈕:

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

這似乎是一個答案是多簡單的拿3個問題的回答,但它究竟是做的伎倆。 此外,對於任何人後來看到這一點,想知道,爲了獲得谷歌的半邊框已採納,我添加了一些代碼,在第一篇文章中爲我工作,因爲在子響應中發佈代碼很難閱讀。 – 2012-03-14 04:58:06

+0

我記得當我試圖找出這個問題時,我想到了同樣的事情。我用它作爲一個超鏈接,本應該是一個相對簡單的任務,或者所以我認爲... – javram 2012-03-14 05:00:01

+0

這需要api 11 – gsscoder 2012-11-23 08:50:31

38

只需添加下面的樣式屬性,在Button標籤:

style="?android:attr/borderlessButtonStyle" 

來源:http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

+4

這是一個很好的答案,但請記住,該屬性添加API 11. – 2013-03-06 02:33:58

+0

而borderlessButtonStyle將background設置爲selectableItemBackground並設置一些填充,僅此而已。 – Anderson 2014-04-17 04:43:24

1

只是櫃面任何人正在尋找輕量級的解決方案,以獲得不支持Holo主題的API的無邊界按鈕(就像我很長一段時間一樣),Im在下面發佈我的解決方案:

<View 
    android:layout_height="1dp" 
    android:layout_width="match_parent" 
    android:background="#505154" 
    android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/btn_Reply" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:background="@android:color/transparent" 
     android:paddingBottom="15dp" android:paddingTop="15dp" 
     android:textColor="#5c5966" 
     android:text="@string/btnReplyText"/> 

    <View 
     android:layout_height="fill_parent" 
     android:layout_width="1dp" 
     android:background="#505154" 
     android:layout_marginBottom="7dp" android:layout_marginTop="7dp"/> 

    <Button 
     android:id="@+id/btn_Delete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:paddingBottom="15dp" android:paddingTop="15dp" 
     android:textColor="#5c5966" 
     android:background="@android:color/transparent" 
     android:text="@string/btnDeleteText" /> 

    <View 
     android:layout_height="fill_parent" 
     android:layout_width="1dp" 
     android:background="#505154" 
     android:text="@string/btnReplyText" 
     android:layout_marginBottom="7dp" android:layout_marginTop="7dp" /> 

    <Button 
     android:id="@+id/btn_Exit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_gravity="center" 
     android:text="@string/btnExitText" 
     android:paddingBottom="15dp" android:paddingTop="15dp" 
     android:textColor="#5c5966" 
     android:background="@android:color/transparent"/> 
</LinearLayout> 

您只需更改顏色和文字以適合自己的背景。祝一切順利!

6

冒着死馬的危險,這裏有另一個(可能更好)選項。 AppCompat v7定義了無邊界按鈕樣式。如果您已經利用該程序兼容性庫,只是去與:

<Button android:text="@string/borderlessButtonText" style="@style/Widget.AppCompat.Button.Borderless" />