如何以编程方式隐藏在Android SDK中的一个按钮 [英] how to programmatically hide a button in android sdk

查看:83
本文介绍了如何以编程方式隐藏在Android SDK中的一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个按钮的相对布局。其重叠在彼此

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:后台=#FFFFFF>


<按钮的android:文本=播放
    机器人:ID =@ + ID /播放
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真正的>
< /按钮>

<按钮的android:文本=停止
    机器人:ID =@ + ID /停止
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真正的>
< /按钮>


< / RelativeLayout的>
 

我想以编程方式在同一时间只显示一个按钮,当它的单击事件被调用。 我尝试着用:

  

playButton.setVisibility(1);

但它不worked.Following是一个例子正是我试图做的。

 为playButton =(按钮)findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(新OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){
             //播放时点击显示停止按钮,隐藏播放按钮

        }
    });
 

解决方案

您可以使用下面的code

 为playButton =(按钮)findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(新OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){
             //播放时点击显示停止按钮,隐藏播放按钮
             playButton.setVisibility(View.GONE);
             stopButton.setVisibility(View.VISIBLE);

        }
    });
 

I have a relative layout which contains two buttons. Which are overlapped on each other.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">


<Button android:text="Play"  
    android:id="@+id/play"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom = "true">
</Button>

<Button android:text="Stop "
    android:id="@+id/stop" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom = "true">
</Button>


</RelativeLayout>

I want to to programmatically show only one button at a time when its click event is called. I tried it with :

playButton.setVisibility(1);

but it does not worked.Following is an example what i am trying to do.

    playButton = (Button) findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
             //when play is clicked show stop button and hide play button

        }
    });

解决方案

You can use the following code

playButton = (Button) findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
             //when play is clicked show stop button and hide play button
             playButton.setVisibility(View.GONE);
             stopButton.setVisibility(View.VISIBLE);

        }
    });

这篇关于如何以编程方式隐藏在Android SDK中的一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆