的onClick后pssed的Android按键设置$ P $ [英] android button setPressed after onClick
问题描述
昨天我注意到通过兼容包中集成老年API级别的碎片的可能性,但那不是真正至关重要的问题。 :)
yesterday I noticed the possibility to integrate Fragments in older API Levels through the Compatibility package, but thats not really essential for the question. :)
我有一个OnClickListener一个按钮
I have a Button with an OnClickListener
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doSomething();
button.setPressed(true);
}
});
实际的点击,因为,它显示为pssed $ P $和释放点击后,该按钮状态不是pssed $ P $,并保持这种方式。
Because of the actual clicking, it is shown as pressed and after releasing the click, the button state is not pressed and stays that way.
是否有持续释放后pssed按钮状态$ P $一个简单的方法? 第一件事,我能想到的将是某种形式的计时器,但似乎是不合理的。
Is there a simple way that keeps the button state pressed after releasing? First thing I can think of would be some sort of timer, but that seems unreasonable.
推荐答案
您可以保留在XML文件中的按钮的状态下绘制的文件夹,然后将其用作背景的按钮。 例如:
You can keep the button states in xml file under drawable folder, then used as background for button. For example:
android:background="@drawable/buttonstate"
buttonstate.xml
buttonstate.xml
<?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/back_focused" />
<item android:drawable="@drawable/back" /> <!-- default -->
</selector>
这篇关于的onClick后pssed的Android按键设置$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!