我有一个按钮,按下后 3 秒就会消失。我想通过触摸屏幕使其再次可见。
public class MainActivity extends Activity {
Runnable buttonRunnable;
Handler buttonHandler = new Handler();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button=(Button)findViewById(R.id.myButton);
buttonRunnable = new Runnable() {
public void run() {
button.setVisibility(View.GONE);
}
};
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
buttonHandler.postDelayed(buttonRunnable, 3000);
}
});
}
private OnTouchListener buttonOnTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final Button button=(Button)findViewById(R.id.myButton);
final LinearLayout linearLayout=(LinearLayout)findViewById(R.id.myLinearLayout);
linearLayout.setClickable(true);
linearLayout.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
button.setVisibility(View.VISIBLE);
}
});
return true;
}
};
}
我可以在 3 秒后隐藏按钮,但我无法让它再次可见。