在Android的圆圈键 [英] Circle Button in Android

查看:141
本文介绍了在Android的圆圈键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个圆形按钮,我的Andr​​oid应用程序,我已经阅读了按钮约9补丁。我还需要一个按钮,改变其颜色,当你preSS它。

I need a circle button for my Android APP, I have read about 9 patch for buttons. I also need that the button changes its color when you press it.

难道9补丁,最好的办法,还是我应该用另一种方法?

Is it 9 patch the best approach, or should I use another method?

在此先感谢。

推荐答案

您可以执行以下操作:

1)创建一个包含一个可绘制/ button_states.xml文件:

1) Create a drawable/button_states.xml file containing:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="false"
        android:drawable="@drawable/button_not_pressed"/>

    <item android:state_pressed="true"
        android:drawable="@drawable/button_pressed"/>

</selector>

2)创建文件绘制/ button_ pressed.xml文件

2) Create the file drawable/button_pressed.xml file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:color="#fff" />
    <corners android:radius="30dp"></corners>
</shape>

3)创建文件绘制/ button_not_ pressed.xml文件

3) Create the file drawable/button_not_pressed.xml file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:color="#000" />
    <corners android:radius="30dp"></corners>
</shape>

4)在按钮使用它像:

4) In the button use it like:

<Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/button_states"
      android:text="New Button"
      android:id="@+id/button1" />

希望它可以帮助!

Hope it helps!!!

这篇关于在Android的圆圈键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆