【问题标题】:replace a button with another under android 4.0在android 4.0下用另一个按钮替换一个按钮
【发布时间】:2011-11-23 10:05:13
【问题描述】:

我的内容视图上有一个“start”按钮,单击它时我想用“stop”按钮替换它。

我已经在xml 中定义了一个“start”和一个“stop”按钮,接下来我该怎么做?非常感谢!

【问题讨论】:

    标签: android events button


    【解决方案1】:

    您需要在代码中引用您的按钮:

    Button stop = (Button) findViewById( R.id.stopButton );
    Button start = (Button) findViewById( R.id.startButton );
    

    为两者添加onClickListeners,当点击开始时添加这些行:

    start.setVisibility( View.GONE );
    stop.setVisibility( View.VISIBLE );
    

    在停止onClickListener 你做相反的事情:

    start.setVisibility( View.VISIBLE );
    stop.setVisibility( View.GONE );
    

    或者您可以让Button 处理启动和停止,然后更改它的文本。

    【讨论】:

      【解决方案2】:

      使用 ToggleButton 来满足此要求.. Toggle Button

      【讨论】:

        猜你喜欢
        • 2021-12-18
        • 1970-01-01
        • 1970-01-01
        • 2021-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-24
        相关资源
        最近更新 更多