2014-09-19 56 views
7

我如何只隐藏复选框,但不复选框文本。 Checkbox以编程方式创建。只隐藏复选框不是在Android中的文本

myCheckBox.setVisibility(View.GONE)隐藏整个复选框,其中还包含文本。我只想显示文字而不是框图标。

期待您的回复。

回答

0

你可以这样做,不要在复选框元素中给文本值,你使用单独的textview来隐藏文本并隐藏复选框。 例

  <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hindustan"/> 
     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="invisible" 
      android:id="@+id/hindustanCB"/> 
+0

不是一个好方法。 – Killer 2015-08-19 14:14:37

7

这个工作对我来说:

Drawable transparentDrawable = new ColorDrawable(Color.TRANSPARENT); 
myCheckBox.setButtonDrawable(transparentDrawable);