harmony 鸿蒙LocationButton

2023-10-30 浏览 (544)

LocationButton

The <LocationButton> security component allows you to obtain temporary precise location permission from the user by their touching the button, eliminating the need for a permission request dialog box.

NOTE

This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.

Child Components

Not supported

APIs

LocationButton

LocationButton()

Creates a Location button with an icon, text, and background.

LocationButton

LocationButton(option:{icon?: LocationIconStyle, text?: LocationDescription, buttonType?: ButtonType})

Creates a Location button that contains the specified elements.

Parameters

NameTypeMandatoryDescription
iconLocationIconStyleNoIcon style of the Location button.
If this parameter is not specified, no icon is contained. Either icon or text, or both, must be set.
textLocationDescriptionNoText on the Location button.
If this parameter is not specified, no text is contained. Either icon or text, or both, must be set.
buttonTypeButtonTypeNoBackground style of the Location button.
If this parameter is not specified, there is no background.

LocationIconStyle

NameDescription
FULL_FILLEDFilled style icon.
LINESLine style icon.

LocationDescription

NameDescription
CURRENT_LOCATIONThe text on the Location button is Current location.
ADD_LOCATIONThe text on the Location button is Add location.
SELECT_LOCATIONThe text on the Location button is Select location.
SHARE_LOCATIONThe text on the Location button is Share location.
SEND_LOCATIONThe text on the Location button is Send location.
LOCATINGThe text on the Location button is Locate.
LOCATIONThe text on the Location button is Location.
SEND_CURRENT_LOCATIONThe text on the Location button is Send current location.
RELOCATIONThe text on the Location button is Relocate.
PUNCH_INThe text on the Location button is Punch in.
CURRENT_POSITIONThe text on the Location button is Current position.

LocationButtonOnClickResult

NameDescription
SUCCESSThe Location button is touched successfully.
TEMPORARY_AUTHORIZATION_FAILEDTemporary authorization fails after the Location button is touched.

Attributes

This component can only inherit the universal attributes of security components

Events

Only the following events are supported.

NameDescription
onClick(event: (event: ClickEvent), result: LocationButtonOnClickResult) => void)Triggered when the component is touched.
result: authorization result.
event: For details, see ClickEvent.

Example

// xxx.ets
@Entry
@Component
struct Index {
  build() {
    Row() {
      Column({space:10}) {
        // Create a default Location button with an icon, text, and background.
        LocationButton().onClick((event: ClickEvent, result: LocationButtonOnClickResult)=>{
          console.info("result " + result)
        })
        // Whether an element is contained depends on whether the parameter corresponding to the element is specified.
        LocationButton({icon:LocationIconStyle.LINES})
        // Create a Location button with only an icon and background.
        LocationButton({icon:LocationIconStyle.LINES, buttonType:ButtonType.Capsule})
        // Create a Location button with an icon, text, and background.
        LocationButton({icon:LocationIconStyle.LINES, text:LocationDescription.CURRENT_LOCATION, buttonType:ButtonType.Capsule})
      }.width('100%')
    }.height('100%')
  }
}

en-us_image_0000001593518280

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkTS-based Declarative Development Paradigm

harmony 鸿蒙@ohos.multimedia.avCastPicker (AVCastPicker)

harmony 鸿蒙Property Animation

harmony 鸿蒙Enums

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

harmony 鸿蒙CheckboxGroup

harmony 鸿蒙DataPanel

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/9dcacf44dc6540efb4932da7cdbd02a7