按键设置pressed()的onClick [英] Button setPressed() onClick

查看:159
本文介绍了按键设置pressed()的onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,

在我的xml文件我有:

in my xml file i have :

<Button
android:id="@+id/button_8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple" 
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="action"            
/>

在我的活动我有:

And in my activity i have that :

public void action (View v)
{
    s = "m";
    changeCouleur("blue");
    v.setPressed(true);
}

当我pressed按钮,它的工作,但按钮不留pressed。

When i pressed the button it's working but the button don't stay pressed.

我不使用的图像这是我使用的颜色:

I don't use an image this is what i use for the color :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item android:state_focused="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#449def"
                android:endColor="#2f6699"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

在此先感谢,如果你发现了一些问题。
请任何人有任何想法?

Thanks in advance if you noticed something wrong. Please anyone have any idea ?

推荐答案

这是我的理解是,你要使用一个按钮来打开的状态关闭/开启,还按钮的状态将清楚地表明该功能的状态。

From what I understand is that you are trying to use a button to turn a state off/on, also the button's state will clearly indicate the feature's state.

如果我是正确的,然后使用自定义的复选框。您将有复选框的不同状态来定义反正选择器(由user1071979提到的)。

If I am correct then use custom check box. You will have to anyways define selector for different states of checkbox (as mentioned by user1071979).

这篇关于按键设置pressed()的onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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