【问题标题】:Visibility of Button按钮的可见性
【发布时间】:2015-01-17 20:12:19
【问题描述】:

如何使按钮不可见,并在需要时设置按钮的文本。这是我试过的代码,这是MainActivity.class。

 getSupportActionBar().hide();

  phno=(EditText)findViewById(R.id.editText3);

}

public void get(View view){
    String ph=phno.getText().toString();
   Button btn=(Button)findViewById(R.id.button3);
   btn.setText("Call"+ph);
   btn.setTextSize(30);
}

这是 xml 文件夹:

EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:ems="10"
    android:id="@+id/editText3"
    android:layout_marginTop="119dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:hint="Enter Phone Number"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ok"
    android:id="@+id/button2"
    android:layout_centerVertical="true"
    android:layout_alignRight="@+id/editText3"
    android:layout_alignEnd="@+id/editText3"
    android:onClick="get"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button3"
    android:layout_alignTop="@+id/button2"
    android:layout_alignLeft="@+id/editText3"
    android:layout_alignStart="@+id/editText3"
    android:visibility="gone"
    />

当我输入数字并单击确定时,没有任何反应。请帮忙,

【问题讨论】:

    标签: java android xml button


    【解决方案1】:
    btn.setVisibility(VIEW.GONE);  //hide
    btn.setVisibility(VIEW.INVISIBLE);//transparent
    

    请参考这里的区别: Android : difference between invisible and gone?

    【讨论】:

      【解决方案2】:
      Button btn=(Button)findViewById(R.id.button);
      btn.setVisibility(View.GONE);
      

      隐藏按钮

      View.GONE
      

      按钮的透明视图使用

      View.INVISIBLE
      

      【讨论】:

      • 有一个错字:b.setVisibility(View.GONE); 应该是btn.setVisibility(View.GONE);
      猜你喜欢
      • 2012-06-15
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 2012-05-31
      • 2013-05-13
      • 2011-10-21
      相关资源
      最近更新 更多