文章40 | 阅读 20979 | 点赞0
| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |
| basement | 输入框基线 | Element类型 | 可直接配置色值,也可引用color资源或引用media/graphic下的图片资源 | ohos:basement="#000000" ohos:basement="$color:black" ohos:basement="$media:media_src" ohos:basement="$graphic:graphic_src" |
<TextField
...
ohos:id="$+id:text_field"
ohos:height="40vp"
ohos:width="200vp"
ohos:left_padding="20vp"
/>
TextField textField = (TextField) findComponentById(ResourceTable.Id_text_field);
String content = textField.getText();
<TextField
...
ohos:background_element="$graphic:background_text_field"
/>
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="40"/>
<solid
ohos:color="#FFFFFF"/>
</shape>
<TextField
...
ohos:hint="Enter phone number or email"
ohos:text_alignment="vertical_center"/>
<TextField
...
ohos:element_cursor_bubble="$graphic:ele_cursor_bubble" />
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="40"/>
<solid
ohos:color="#6699FF"/>
<stroke
ohos:color="#0066FF"
ohos:width="10"/>
</shape>
<TextField
...
ohos:left_padding="24vp"
ohos:right_padding="24vp"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"/>
<TextField
...
ohos:multiple_lines="true"/>
textField.setEnabled(false);
textField.setFocusChangedListener((component, isFocused) -> {
if (isFocused) {
// 获取到焦点
...
} else {
// 失去焦点
...
}
});
<TextField
...
ohos:basement="#000099" />
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_parent"
ohos:background_element="#FF000000"
ohos:orientation="vertical">
<StackLayout
ohos:top_margin="60vp"
ohos:width="match_parent"
ohos:height="match_content"
ohos:layout_alignment="center">
<TextField
ohos:id="$+id:name_textField"
ohos:width="600vp"
ohos:height="match_content"
ohos:multiple_lines="false"
ohos:left_padding="24vp"
ohos:right_padding="24vp"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:min_height="44vp"
ohos:text_size="18fp"
ohos:layout_alignment="center"
ohos:text_alignment="vertical_center"
ohos:background_element="$graphic:background_text_field"
ohos:hint="Enter phone number or email" />
<Text
ohos:visibility="hide"
ohos:id="$+id:error_tip_text"
ohos:width="match_content"
ohos:height="match_content"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:right_margin="20vp"
ohos:text="Incorrect account or password"
ohos:text_size="18fp"
ohos:text_color="red"
ohos:layout_alignment="right"/>
</StackLayout>
<TextField
ohos:top_margin="40vp"
ohos:id="$+id:password_text_field"
ohos:width="600vp"
ohos:height="match_content"
ohos:multiple_lines="false"
ohos:left_padding="24vp"
ohos:right_padding="24vp"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:min_height="44vp"
ohos:text_size="18fp"
ohos:layout_alignment="center"
ohos:text_alignment="vertical_center"
ohos:background_element="$graphic:background_text_field"
ohos:hint="Enter password" />
<Button
ohos:top_margin="40vp"
ohos:id="$+id:ensure_button"
ohos:width="120vp"
ohos:height="35vp"
ohos:background_element="$graphic:background_btn"
ohos:text="Log in"
ohos:text_size="20fp"
ohos:layout_alignment="horizontal_center"/>
</DirectionalLayout>
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="40"/>
<solid
ohos:color="white"/>
<stroke
ohos:color="black"
ohos:width="6"/>
</shape>
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="35"/>
<solid
ohos:color="white"/>
</shape>
// 当点击登录,改变相应组件的样式
Button button = (Button) findComponentById(ResourceTable.Id_ensure_button);
button.setClickedListener((component -> {
// 显示错误提示的Text
Text text = (Text) findComponentById(ResourceTable.Id_error_tip_text);
text.setVisibility(Component.VISIBLE);
// 显示TextField错误状态下的样式
ShapeElement errorElement = new ShapeElement(this, ResourceTable.Graphic_background_text_field_error);
TextField textField = (TextField) findComponentById(ResourceTable.Id_text_field);
textField.setBackground(errorElement);
// TextField失去焦点
textField.clearFocus();
}));
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="40"/>
<solid
ohos:color="gray"/>
<stroke
ohos:color="#E74C3C"
ohos:width="6"/>
</shape>
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/Forever_wj/article/details/118117720
内容来源于网络,如有侵权,请联系作者删除!