我试图在点击时在图像按钮上添加某种阴影.有可能吗?
所以我有按钮,我希望它点击它时看起来会被推.所以我创建了这样的新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"
android:drawable="@color/btn_pushed"
/>
<item
android:drawable="@drawable/btn" />
</selector>
Run Code Online (Sandbox Code Playgroud)
好吧它工作正常,但我有50个按钮,我必须为他们所有人制作新的图像.这是很多工作,是否可以在其上添加某种阴影?还是会让它看起来如此推动?
所以我找到了一个解决方案,我在这里为功能读者添加它.诀窍是使用.我在这里找到答案http://belencruz.com/2012/12/rounded-button-with-shadow-in-android/ 我的代码现在:
<?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"
>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn" />
<item android:drawable="@color/transparent"/>
</layer-list>
</item>
<item
android:drawable="@drawable/btn" />
</selector>
Run Code Online (Sandbox Code Playgroud)
工作真的很好!
| 归档时间: |
|
| 查看次数: |
13221 次 |
| 最近记录: |