[Daily HarmonyOS Next Knowledge] Semi-modal Page Margins, Mouse Hover on List Items, Default Options for Select Components, Different Text Sizes, String Encoding
1. Can HarmonyOS ArkTS semi-modal pages set left and right margins for mobile phones?
Since API 12, the width of semi-modals can be set.
Reference link: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5#bindsheet
2. For Image components traversed by HarmonyOS LazyForEach, how to handle mouse hover scenarios to target the selected Image rather than the entire outer component?
Assign the index to a variable in onHover
, then judge whether the variable matches the current index in the specific Image attribute and change the attribute value if they match.
.onHover((isHover?: boolean) => {
if (isHover) {
this.hoverIndex = index;
}
})
3. How to set a default value for the HarmonyOS ArkTS select component?
Can the select component set a default value to automatically select an option when the program starts without manual selection?
Use the selected
attribute to set the index of the initial option in the drop-down menu.
Documentation link: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-select-V5#selected
selected(value: number | Resource)
Sets the index of the initial option in the drop-down menu (index 0 for the first item). If selected
is not set or an invalid value is provided, the default selection is -1 (no item selected). If set to undefined
or null
, the first item is selected.
4. How to use different font sizes for a single line of text in HarmonyOS?
How to implement different font sizes for a single line of text while considering internationalization and left-right position changes?
Use Span
to fill partial content and configure the direction
attribute for left-right position changes.
5. HarmonyOS string encoding issues?
Which encoding in BufferEncoding
is equivalent to Java's GB18030 encoding, used in the SM3 digest algorithm?
API 12 supports this.
Reference document: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-util-V5#textencoder
TextEncoder
encodes strings into byte arrays and supports multiple encoding formats.
Note: The number of bytes per character varies by encoding format. Specify the encoding format explicitly when using TextEncoder
to ensure correct encoding results.
Top comments (0)