我已经在网络上搜索了一周左右的时间来获得有关如何制作彩色凸起按钮的示例或教程,但没有成功。
我希望在我的应用中实现以下内容以获得更好的用户界面体验。
我确实遇到过卡片 View ,但是当你编写一个包含很多按钮的大程序时,xml 代码会因为这个卡片 View 而变得更大。
因此,如果对以下问题有任何快速简单的解决方案,请告诉我。
谢谢
已更新
Normal button
and with color
最佳答案
我认为您实际上想要提升按钮。不要使用卡片,因为它需要更多资源。用于 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/