美文网首页
鸿蒙第5(3)按钮切换图片文字的步骤

鸿蒙第5(3)按钮切换图片文字的步骤

作者: 游私塾白书生 | 来源:发表于2022-05-17 14:55 被阅读0次

1.写好xml页面并设置号开关和文本的id

2.代码书写方法

// 获取开关

        swibtn=(Switch)findComponentById(ResourceTable.Id_swiBtn);

//        获取文本

        text1=(Text)findComponentById(ResourceTable.Id_text1);

        // 开关绑定  状态是否为监听

            swibtn.setCheckedStateChangedListener(new mySwithChangeListener());

    }

//内部类

    public class mySwithChangeListenerimplements AbsButton.CheckedStateChangedListener{

// 既然重建  需要重写

        @Override

        public void onCheckedChanged(AbsButton absButton, boolean b) {

if (absButton==swibtn){

//开关

                    text1.setText("当前的状态"+b);

               }

}

}

相关文章

网友评论

      本文标题:鸿蒙第5(3)按钮切换图片文字的步骤

      本文链接:https://www.haomeiwen.com/subject/gplnurtx.html