Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式删除单选按钮并仅显示文本_Android_Radio Button_Drawable - Fatal编程技术网

Android 以编程方式删除单选按钮并仅显示文本

Android 以编程方式删除单选按钮并仅显示文本,android,radio-button,drawable,Android,Radio Button,Drawable,我有一个单选按钮,文本显示如下: 0关于,这里0表示它是一个单选按钮,我想以渐进方式删除单选按钮,只显示文本“关于”如何操作 我试过: radioButton.setButtonDrawable(android.R.color.transparent);// only hides the radio button radioButton.setButtonDrawable(android.R.empty);// not working 提前感谢。xml布局: <LinearLayo

我有一个单选按钮,文本显示如下:

0关于
,这里0表示它是一个单选按钮,我想以渐进方式删除单选按钮,只显示文本“关于”如何操作

我试过:

radioButton.setButtonDrawable(android.R.color.transparent);// only hides the radio button
radioButton.setButtonDrawable(android.R.empty);// not working
提前感谢。

xml布局:

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ButtonText" />

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>
xml布局:

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ButtonText" />

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>

可以在运行时使用setText()方法设置setText

radioButton.setText(“关于”)


可能是您想要的。

您可以在运行时使用setText()方法设置setText

radioButton.setText(“关于”)


可能是您想要的。

只是不要将文本设置为
单选按钮
,而是使用单独的
文本视图
作为文本

然后,当您想隐藏单选按钮时,只需使用
setVisibility(View.GONE)
(View.GONE将隐藏整个内容,没有任何空间)并再次显示
setVisibility(View.VISIBLE)

下面是一个关于如何使用它的布局的小示例:

XML


只需完全不要将文本设置为
单选按钮
,而是使用单独的
文本视图
作为文本

然后,当您想隐藏单选按钮时,只需使用
setVisibility(View.GONE)
(View.GONE将隐藏整个内容,没有任何空间)并再次显示
setVisibility(View.VISIBLE)

下面是一个关于如何使用它的布局的小示例:

XML

  • 是否尝试使用以下行隐藏按钮可绘制:

    radioButton.setButtonDrawable(新的彩色Drawable(0xFFFFFF))

这将隐藏左侧的可拔模件。

  • 是否尝试使用以下行隐藏按钮可绘制:

    radioButton.setButtonDrawable(新的彩色Drawable(0xFFFFFF))


这将隐藏左侧的可绘制图形。

为什么不设置可视性(View.GONE)?我不明白
//只隐藏单选按钮
@mc_fish setvisability(View.GONE)?还将删除文本Use radioButton和文本视图(以显示文本)。。然后使用radioButton.setVisibility(View.GONE)…如果不需要单选图标,为什么要使用radioButton?为什么不使用切换按钮?为什么不设置可视性(View.GONE)?我不明白//只隐藏单选按钮@mc_fish setvisability(View.GONE)?还将删除文本Use radioButton和文本视图(以显示文本)。。然后使用radioButton.setVisibility(View.GONE)…如果不需要单选图标,为什么要使用radioButton?为什么不使用切换按钮?它也会隐藏文本我不明白为什么这个
radioButton.setButtonDrawable(android.R.color.transparent)不起作用。你能澄清一下这个问题吗?也许可以提供一些你需要的信息。这只会隐藏单选按钮,但会占用空间。我认为@CRUSADER是正确的。我将用一个示例代码更新我的答案。它还将隐藏文本我不明白为什么这个
radioButton.setButtonDrawable(android.R.color.transparent)不起作用。你能澄清一下这个问题吗?也许可以提供一些你需要的信息。这只会隐藏单选按钮,但会占用空间。我认为@CRUSADER是正确的。我会用一个示例代码更新我的答案。谢谢你的帮助,但我在这里有一个问题,就像我在一个放射组中使用3个单选按钮一个接一个地放置感谢你的帮助,但我在这里有一个问题,就像我在一个放射组中使用3个单选按钮一个接一个地放置一样
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Radio button text" />

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toggle visibility" />

</LinearLayout>
final RadioButton radioButton = (RadioButton) findViewById(R.id.radioButton1);
findViewById(R.id.toggleButton1).setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        if(radioButton.getVisibility() == View.VISIBLE) {
            radioButton.setVisibility(View.GONE);
        }
        else if(radioButton.getVisibility() == View.GONE) {
            radioButton.setVisibility(View.VISIBLE);
        }
    }
});