3

我在 Android 2.3.3 中有一个应用程序。里面有几个按钮。我想要一个类似于 qwerty 键盘的功能(用于按钮),当我们按下一个键或一个字母时,该字符将显示几分之一秒,就在该字符出现的位置上方键盘。

我们有内置的任何此类属性吗?

如果没有这样的东西,我正在为我的按钮使用背景颜色,并且很难记下按钮是否被单击。我们能否以某种方式使其可见该按钮已被单击。

4

3 回答 3

1

您在可绘制文件夹中寻找类似这样的选择器。要引用它,只需将其称为可绘制对象。

<?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>
于 2012-12-12T09:24:19.510 回答
0

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.

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.

于 2012-12-12T09:21:09.757 回答
0

使用以下xmlUIbutton选择:

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> 

以下是用于绑定的代码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); 
}
于 2012-12-12T09:31:58.913 回答