[英]How do I add animation / styling to a button? Android Studio
我有一個按鈕
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:onClick="loginIsClicked"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:background="@drawable/button"
android:text="@string/Auth"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16sp"
android:enabled="false" />
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/red"/>
<corners android:radius="10dp"/>
</shape>
如何為默認按鈕中使用的按鈕添加動畫?
示例:在此處輸入圖像描述
如果我理解正確,您正在尋找的是漣漪。 如下將您的形狀包裹在波紋中,並提供您的波紋顏色:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/rippleColor">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/red"/>
<corners android:radius="10dp"/>
</shape>
</item>
</ripple>
添加MaterialButton
。
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Button" />
另外不要忘記在styles.xml
文件Theme.MaterialComponents.Light.DarkActionBar
主題Theme.AppCompat.Light.DarkActionBar
更改為Theme.MaterialComponents.Light.DarkActionBar
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.