您当前的位置: 首页 >  ui

蓝不蓝编程

暂无认证

  • 6浏览

    0关注

    706博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

零基础学鸿蒙编程-UI控件_RadioButton

蓝不蓝编程 发布时间:2021-10-17 21:50:46 ,浏览量:6

什么是RadioButton、RadioContainer

RadioButton和RadioContainer是用来显示一组单选框的,RadioButton就是单个单选框,RadioContainer就是这个组.

基础样例 1.展示一组单选框 效果图

代码

1). 布局文件:activity_main.xml



    

    

2). java代码:

Text text = (Text) findComponentById(ResourceTable.Id_text);
RadioContainer container = (RadioContainer) findComponentById(ResourceTable.Id_radioContainer);
container.setMarkChangedListener((radioContainer, index) -> {
    text.setText("当前选中 : " + index);
});

完整代码:

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Text text = (Text) findComponentById(ResourceTable.Id_text);
        RadioContainer container = (RadioContainer) findComponentById(ResourceTable.Id_radioContainer);

        container.setMarkChangedListener((radioContainer, index) -> {
            text.setText("当前选中 : " + index);
        });
    }
}
基础样例完整源代码

https://gitee.com/hspbc/harmonyos_demos/tree/master/radioButtonDemo

常用属性说明 属性名用途ohos:width设置控件宽度,可设置为:match_parent(和父控件一样),match_content(按照内容自动伸缩),设置固定值(如200vp)ohos:height设置控件高度,可设置为:match_parent(和父控件一样),match_content(按照内容自动伸缩),设置固定值(如200vp)ohos:layout_alignment在父控件内对齐方式,可选值:left:居左;start:居左;center:居中;right:居右;end:居右;top:居上;bottom:居下;horizontal_center:水平居中;vertical_center:垂直居中ohos:background_element设置背景,可以是色值(如#FF0000)或图片等ohos:visibility可选值: visible(显示), invisible(隐藏,但是仍占据UI空间),hide(隐藏,且不占UI空间)ohos:text设置文本内容ohos:text_size设置字号ohos:text_color设置颜色,样例:ohos:text_color="#FF0000",ohos:text_color=“red”ohos:italic设置是否斜体,可选值:true:斜体;false:正常字体ohos:text_color_on设置选中时,文字颜色,样例:ohos:text_color_on="#FF0000",ohos:text_color_off设置未选中时,文字颜色,样例:ohos:text_color_on="#00FF00",ohos:marked设置是否选中,可选值:true:选中;false:未选中

更多属性及实际效果,可以在开发工具里自行体验.

零基础系列

《零基础学安卓编程》 《零基础学Java编程》 《零基础学鸿蒙编程》

关于我

厦门大学计算机专业 | 前华为工程师 专注《零基础学编程系列》,包含:Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙 全网可关注:花生皮编程

关注
打赏
1639405877
查看更多评论
立即登录/注册

微信扫码登录

0.0411s