日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HarmonyOS之常用组件ToastDialog的功能和使用

發布時間:2024/5/21 编程问答 73 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HarmonyOS之常用组件ToastDialog的功能和使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、ToastDialog 的使用
  • ToastDialog 是在窗口上方彈出的對話框,是通知操作的簡單反饋。ToastDialog 會在一段時間后消失,在此期間,用戶還可以操作當前窗口的其他組件。
  • 創建一個 ToastDialog:
new ToastDialog(getContext()).setText("This is a ToastDialog").show();
    • ToastDialog 效果圖如下:

  • 設置位置:
new ToastDialog(getContext()).setText("This is a ToastDialog displayed in the middle").setAlignment(LayoutAlignment.CENTER).show();
    • 設置顯示位置的效果:

  • 自定義 ToastDialog 的 Component:
    • Java 代碼示例:
DirectionalLayout toastLayout = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_layout_toast, null, false);new ToastDialog(getContext()).setContentCustomComponent(toastLayout).setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT).setAlignment(LayoutAlignment.CENTER).show();
    • layout_toast.xml 布局:
<?xml version="1.0" encoding="utf-8"?><DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_content"ohos:width="match_content"ohos:orientation="vertical"><Textohos:id="$+id:msg_toast"ohos:height="match_content"ohos:width="match_content"ohos:left_padding="16vp"ohos:right_padding="16vp"ohos:top_padding="4vp"ohos:bottom_padding="4vp"ohos:layout_alignment="center"ohos:text_size="16fp"ohos:text="This is a ToastDialog for the customized component"ohos:background_element="$graphic:background_toast_element"/></DirectionalLayout>
    • 其中 background_toast_element.xml:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:shape="rectangle"><cornersohos:radius="30vp"/><solidohos:color="#66808080"/></shape>
    • 自定義 Component 效果:

二、場景示例
  • 自定義視圖:添加多個視圖的場景。自定義多個組件的效果如下:

  • layout_toast_and_image.xml 代碼示例:
<?xml version="1.0" encoding="utf-8"?><DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_content"ohos:width="match_content"ohos:orientation="horizontal"><Imageohos:width="30vp"ohos:height="30vp"ohos:scale_mode="inside"ohos:image_src="$media:icon"/><Textohos:id="$+id:msg_toast"ohos:height="match_content"ohos:width="match_content"ohos:background_element="$graphic:background_toast_element"ohos:bottom_padding="4vp"ohos:layout_alignment="vertical_center"ohos:left_padding="16vp"ohos:right_padding="16vp"ohos:text="This is a ToastDialog with An Image"ohos:text_size="16fp"ohos:top_padding="4vp"/></DirectionalLayout>
    • 其中 background_toast_element.xml:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:shape="rectangle"><cornersohos:radius="30vp"/><solidohos:color="#66808080"/></shape>
    • Java 示例代碼:
DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_layout_toast_and_image, null, false);new ToastDialog(getContext()).setContentCustomComponent(layout).setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT).setAlignment(LayoutAlignment.CENTER).show();

總結

以上是生活随笔為你收集整理的HarmonyOS之常用组件ToastDialog的功能和使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。