简体   繁体   English

关于按钮点击android

[英]Regarding Button Clicking in android

I have an application in Android 2.3.3. 我在Android 2.3.3中有一个应用程序。 There are few buttons in it. 它里面的按钮很少。 I want a functionality (for the buttons) similar to that of qwerty keyboard, where in when we press a key or a letter, that character will be shown for a fraction of a second, just above the place where that character is present in the keyboard. 我想要一个类似于qwerty键盘的功能(对于按钮),当我们按下一个键或一个字母时,该字符将在几分之一秒内显示,就在该字符存在于该字符的位置上方键盘。

Do we have any such kind of properties built in? 我们内置了这样的房产吗?

If there is no such thing, i am using a background color to my buttons and it's hard to get a note of whether the button is clicked or not. 如果没有这样的东西,我在我的按钮上使用背景颜色,很难记下按钮是否被点击。 Can we somehow make it visible that the button is clicked. 我们可以以某种方式使按钮被单击可见。

Your looking for a selector somehting like this inside your drawable folder. 你在drawable文件夹中寻找一个像这样的选择器。 To reference it just call it like a drawable. 引用它只是称它为drawable。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/buttonpressed" />
<item android:drawable="@drawable/buttonnotpressed" /> <!-- default -->
</selector>

well, it seems to me like you should try and create an XML file that describes the button different states instead of what you're currently doing. 好吧,在我看来,你应该尝试创建一个描述按钮不同状态的XML文件,而不是你当前正在做的事情。

if you still want to show the buttons layout as a popup when the button ius pressed, you should create a view and add it when intercepting the MotionEvent.ACTION_DOWN and remove it when intercepting the MotionEvent.ACTION_UP . 如果你仍然想显示的按钮布局作为一个弹出按钮时按下曼月乐,你应该创建一个视图,并拦截时添加它MotionEvent.ACTION_DOWN和拦截时将其删除MotionEvent.ACTION_UP

Use the below xml for UI button selection : 使用以下xml进行UI button选择:

buttonselection.xml : buttonselection.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="false" 
  android:state_selected="false" 
  android:state_pressed="false" 
  android:drawable="@drawable/image you want to display on page load"/> 
<item android:state_focused="false" 
  android:state_selected="true" 
  android:state_pressed="false" 
  android:drawable="@drawable/image you want to display on selection"/> 
<item android:state_focused="true" 
  android:state_selected="false" 
  android:state_pressed="false" 
  android:drawable="@drawable/image you want to display on page load"/> 
<item android:state_focused="true" 
  android:state_selected="true" 
  android:state_pressed="false" 
  android:drawable="@drawable/image you want to display on selection"/> 
<item android:state_pressed="true" 
  android:drawable="@drawable/image you want to display on selection"/> 
</selector> 

and below is the code for binding with xml : 以下是与xml绑定的代码:

 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.yourLayout);
   ImageButton btYourLayoutBtn = (ImageButton)findViewById(R.id.yourbuttonid);
  btYourLayoutBtn .setImageResource(R.drawable.buttonselection);
  btYourLayoutBtn .setOnClickListener(this); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM