Android,设计自定义按钮(渐变和动画)
在我的应用程序中,我想将渐变应用于按钮。我写了下面的代码,结果是完美的。
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<solid
android:color="#FF000000"/>
</shape>
</item>
<item>
<shape>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<gradient
android:startColor="#FFB0B0B0"
android:centerColor="#FFFFFFFF"
android:endColor="#FFB0B0B0"
android:angle="315"/>
<corners
android:radius="3dp"/>
</shape>
</item>
</layer-list>
但我的问题是,当我单击此按钮时,我没有像原始效果或动画那样的效果或动画。因此,我想在它上面添加一些效果,当用户单击它时,按钮会变大,当释放按键时,按钮会恢复到原来的状态。
请指导我。谢谢 :)
In my application I want to apply gradient to Button. I have written following code and the result is perfect.
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<solid
android:color="#FF000000"/>
</shape>
</item>
<item>
<shape>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<gradient
android:startColor="#FFB0B0B0"
android:centerColor="#FFFFFFFF"
android:endColor="#FFB0B0B0"
android:angle="315"/>
<corners
android:radius="3dp"/>
</shape>
</item>
</layer-list>
But my problem is, when I click on this button I have no effect or animation such as original one. Therefor, I want to add some effect on it that when user clicks on it the button becomes bigger and when released the key, the button comeback to its situation.
guide me please. thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅适用于按钮的背景,但您尚未为不同的事件(例如单击、悬停等)指定任何内容。
为此,您必须创建另一组样式并在选择器中设置它们,如我的 上一个答案 并将该选择器作为按钮的背景
This is for only background of button but you have not specified anything for different events like click, hover, etc.
For that you have to create another set of styles and set them in selector as in my previous answer and make that selector as background of your button