android按钮闩锁行为
我不熟悉android和java,所以请友好一点——我知道我的方法不正确 我希望在按下按钮时有一个状态(进程正在运行)(闩锁状态) 我在xml中尝试了以下内容android按钮闩锁行为,android,button,layout,Android,Button,Layout,我不熟悉android和java,所以请友好一点——我知道我的方法不正确 我希望在按下按钮时有一个状态(进程正在运行)(闩锁状态) 我在xml中尝试了以下内容 <Button android:id="@+id/my_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click me" android:onClick="
<Button
android:id="@+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:onClick="otherClicked">
</Button>
试试这个
//如何在XML中定义按钮的示例
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
尝试使用onTouchListener
brown = (Button) findViewById(R.id.my_btn);
brown.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
//down clicked
} else if (event.getAction() == (MotionEvent.ACTION_UP)) {
//button release
}
return false;
}
});
对于两个州,Android有一个-请检查一下。按钮具有称为“仅单击”的行为,但切换按钮具有打开/关闭状态。希望我对您期望的答案没有错。这是用于单击按钮的。他正在询问锁上按钮的事,意思是按住按钮(我猜)。
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
}
}
public void selfDestruct(View view) {
Toast.makeText(getBaseContext(), "isPressed", Toast.LENGTH_LONG).show();
}
brown = (Button) findViewById(R.id.my_btn);
brown.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
//down clicked
} else if (event.getAction() == (MotionEvent.ACTION_UP)) {
//button release
}
return false;
}
});