Q
材質按鈕上的圓角
11
A
回答
14
您需要繼承該樣式。
添加到您的styles.xml:
<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/rounded_shape</item>
</style>
添加文件繪製/ rounded_shape.xml:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/colorAccent" >
</solid>
<corners
android:radius="11dp" >
</corners>
</shape>
最後,在你的佈局:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
style="@style/AppTheme.RoundedCornerMaterialButton"/>
編輯:更新答案使用主題的顏色而不是硬編碼。
0
也是另一種簡單的方法是將其套在cardView,一定要設置cardView的layout_width和layout_height爲wrap_content,也都需要的保證金的按鈕將需要應適用於cardView
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="40dp"
app:elevation="10dp">
<android.support.v7.widget.AppCompatButton
android:id="@+id/login_twitter"
android:tag="login_twitter"
android:layout_width="300dp"
android:layout_height="60dp"
android:paddingLeft="10dp"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:textColor="@color/blue_grey_ligthen_5"
android:drawableLeft="@drawable/twitter"
android:background="@color/twitter"
android:text="@string/login_with_twitter" />
</android.support.v7.widget.CardView>
0
我會告訴你我的確切解決方案。在選擇器標籤內部,您可以放置項目(按鈕的功能)
選擇器標籤的第二項具有相反的行爲。可以添加多達選擇器(按鈕的行爲) 添加此可繪製的XML作爲背景按鈕的Android:背景=「@繪製/此xml」
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffffff"> <!-- this is the ripple color(first touch color changes into this color) -->
<item>
<selector>
<item android:state_enabled="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- default button color -->
<solid android:color="@color/colorPrimary"></solid>
<corners android:radius="151dp"></corners>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- button disabled color opposite behaviour -->
<solid android:color="#e9d204"></solid>
<corners android:radius="151dp"></corners>
</shape>
</item>
</selector>
</item>
<item>
<selector>
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- button first touch of your finger color -->
<solid android:color="#1989fa"></solid>
<corners android:radius="151dp"></corners>
</shape>
</item>
</selector>
</item>
<item>
<selector>
<item android:state_hovered="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- hovered with a note pencil -->
<solid android:color="#4affffff"></solid>
<corners android:radius="151dp"></corners>
</shape>
</item>
</selector>
</item>
</ripple>
相關問題
- 1. Android中的材質圓形按鈕?
- 2. 角材質按鈕禁用風變化
- 3. HTML材質設計按鈕
- 4. [安卓L] Android的材質圓形按鈕
- 5. 按鈕的圓角
- 6. 如何在角度材質中設置按鈕CSS的樣式?
- 7. 將按鈕添加到帶有角度材質的md-tab
- 8. 角質材料mdMenu
- 9. 角度材質nvd3
- 10. 角4與材質
- 11. 圓角按鈕ASP.NET
- 12. 箭頭按鈕上的圓角
- 13. HTML按鈕上的便攜式圓角
- 14. 如何使用角度材質觸發按鈕選擇?
- 15. 如何設置不屬於材質組件的材質角度材質
- 16. UIImage的按鈕圓角
- 17. Vue材質 - 造型表格按鈕?
- 18. Angular2材質:對角度材質輸入的自定義驗證
- 19. kivy中的圓角按鈕角落
- 20. 角度 - 材質 - 測試 - $ mdSidenav
- 21. 在角2材質滑塊
- 22. 角材質CSS md-autocomplete:focus
- 23. 角度材質md-select
- 24. 角材質輸入控制
- 25. md-tab,右上角的按鈕,角材料
- 26. AngularJS材質設計 - 按鈕盤旋上的md顏色
- 27. 如何在Android中的材質按鈕上使用光波紋
- 28. CSS/AngularJS,AngularJS材質按鈕上的文字方向
- 29. 圖像圓角按鈕JavaFX
- 30. 圓角按鈕爲IE8
然而,這將刪除按鈕的連鎖反應。如何獲得定製按鈕的連鎖效應? – ssudaraka
@SupunSudaraka http://stackoverflow.com/a/24530169/401025 –
@LostinBielefeld謝謝,我會試試這個。 – ssudaraka