Android按钮悬停事件

Android按钮悬停事件,第1张

概述我使用 XML文件显示一个具有2种状态的按钮(正常,按下).如何确定按下按钮的时间?是否有像onClick这样的事件 – > onPressed或我怎样才能找到它? 这是我使用的XML文件: <?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/andro 我使用 XML文件显示一个具有2种状态的按钮(正常,按下).如何确定按下按钮的时间?是否有像onClick这样的事件 – > onpressed或我怎样才能找到它?

这是我使用的XML文件:

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID" >    <item androID:state_focused="true" androID:state_pressed="false" androID:drawable="@drawable/buttonbluepressed" />    <item androID:state_focused="true" androID:state_pressed="true" androID:drawable="@drawable/buttonbluepressed" />    <item androID:state_focused="false" androID:state_pressed="true" androID:drawable="@drawable/buttonbluepressed" />    <item androID:drawable="@drawable/buttonblue"/></selector>

以下是我如何使用它:

<button    androID:ID="@+ID/button_choose"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:background="@drawable/choose_button"    androID:onClick="onbuttonClicked"    androID:text="@string/button_choose" />
解决方法 你可以使用 setOnTouchListener作为:

button.setontouchListener(new OntouchListener() {            @OverrIDe            public boolean ontouch(VIEw v,MotionEvent event) {                if(event.getAction() == MotionEvent.ACTION_DOWN){                    //button pressed                }                if(event.getAction() == MotionEvent.ACTION_UP){                     //finger was lifted                }                return false;            }        });
总结

以上是内存溢出为你收集整理的Android按钮悬停事件全部内容,希望文章能够帮你解决Android按钮悬停事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1122906.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存