<?xml version="1.0" encoding="utf-8"?><state-container xmlns:ohos="http://schemas.huawei.com/res/ohos";> <item ohos:state="component_state_checked" ohos:element="$media:rbyes"/> <item ohos:state="component_state_empty" ohos:element="$media:rbno"/></state-container>
新建一个复选框的xml样式文件checkbox_state.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?><state-container xmlns:ohos="http://schemas.huawei.com/res/ohos";> <item ohos:state="component_state_checked" ohos:element="$media:cbyes"/> <item ohos:state="component_state_empty" ohos:element="$media:cbno"/></state-container>
3. 在ability_main布局文件中加入单选按钮、复选框组件标签,将每个RadioButton的check_element设置为radiobutton_state,将每个Checkbox的check_element设置为checkbox_state。
<RadioButton ohos:height="match_content" ohos:width="match_content" ohos:text="男" ohos:text_size="20fp" ohos:margin="20vp" ohos:background_element="$graphic:radionbutton_state"/>
<Checkbox ohos:height="match_content" ohos:width="match_content" ohos:top_margin="50vp" ohos:alignment="left" ohos:text="排球" ohos:margin="20vp" ohos:text_size="20fp" ohos:check_element="$graphic:checkbox_state"/>
在模拟器中运行,就看到自己设置的美美的样式了。
这样一来,是不是简约又美美的?
需要注意的是:
花粉社群VIP加油站
猜你喜欢