我想要在打开活动后以及点击栏中的项目显示按钮
后自动隐藏按钮 @Override
public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
Button bt_call = (Button) findViewById(R.id.bt_call);
if (i == R.id.action_hide) {
if(button1IsVisible==true)
{
bt_call.setVisibility(View.GONE);
button1IsVisible = false;
}
else if(button1IsVisible==false)
{
bt_call.setVisibility(View.VISIBLE);
button1IsVisible = true;
}
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:1)
当活动开始时设置按钮隐藏的可见性..
button.setVisibility(View.GONE);
然后在操作栏的图标中点击监听器......
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_other1:
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button.setVisibility(View.VISIBLE);
}
});
break;
default:
break;
}
// Return false to allow normal menu processing to proceed,
// true to consume it here.
return false;
}
答案 1 :(得分:0)
正确检查特定按钮的可见性,然后显示/隐藏。以下是一个示例:
if (bt_call.getVisibility() == View.VISIBLE) {
bt_call.setVisibility(View.GONE);
} else {
bt_call.setVisibility(View.VISIBLE);
}
注意:声明按钮Globally
,而不是点击事件!
答案 2 :(得分:0)
我想在打开活动后点击项目后自动隐藏按钮 ation bar show button
首先,您需要将bt_call
设置为onCreate
方法中不可见的内容,例如@Devyani Kotadiya所说的
Button bt_call;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_xml);
bt_call= (Button) findViewById(R.id.bt_call);
bt_call.setVisibility(View.INVISIBLE);
}
然后实现如下
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_hide:
if (button1IsVisible.getVisibility() == View.VISIBLE)
{
bt_call.setVisibility(View.INVISIBLE);
}
else
bt_call.setVisibility(View.VISIBLE);
break;
}
return super.onOptionsItemSelected(item);
}