android - 如何制作android凸起按钮?

标签 android android-5.0-lollipop android-button

我已经在网络上搜索了一周左右的时间来获得有关如何制作彩色凸起按钮的示例或教程,但没有成功。

我希望在我的应用中实现以下内容以获得更好的用户界面体验。

我确实遇到过卡片 View ,但是当你编写一个包含很多按钮的大程序时,xml 代码会因为这个卡片 View 而变得更大。

因此,如果对以下问题有任何快速简单的解决方案,请告诉我。

谢谢

enter image description here

已更新

            Normal button 

enter image description here

and with color 

enter image description here

最佳答案

我认为您实际上想要提升按钮。不要使用卡片,因为它需要更多资源。用于 Lollipop 设备

<Button
    ...
    android:stateListAnimator="@anim/my_animator" />

并在资源中的 anim 文件夹中创建 my_animator.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:state_enabled="true">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="@integer/button_pressed_animation_duration"
                            android:valueTo="@dimen/button_pressed_z_material"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="elevation"
                            android:duration="0"
                            android:valueTo="@dimen/button_elevation_material"
                            android:valueType="floatType"/>
        </set>
    </item>
    <!-- base state -->
    <item android:state_enabled="true">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="@integer/button_pressed_animation_duration"
                            android:valueTo="0"
                            android:startDelay="@integer/button_pressed_animation_delay"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="elevation"
                            android:duration="0"
                            android:valueTo="@dimen/button_elevation_material"
                            android:valueType="floatType" />
        </set>
    </item>
    ...
</selector>

关于android - 如何制作android凸起按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29315050/

相关文章:

Android Studio 为新项目创建项目模板

android - 如何自定义 float 操作按钮形状?

java - HttpURLconnection 持续返回错误 - Android

android - native 应用程序在 Android L 上崩溃

Android 5.0 Lollipop 通知全音不播放

android - 应用程序如何在 Lollipop 上使用系统权限

android - 如何在 Button 自己的 onClick 方法中删除它?

android-layout - 在android按钮中对齐自动换行文本

Android服务无限期运行

java - 如何查询 queryDocumentSnapshot Firestore 内的文档字段