提交 7c791789 编写于 作者: 王江颖 提交者: Gitee

Merge branch 'OpenHarmony-3.2-Beta2' of gitee.com:openharmony/docs into OpenHarmony-3.2-Beta2

Signed-off-by: N王江颖 <wangjiangying@huawei.com>
# Standard NFC Card Emulation # Standard NFC Card Emulation
The cardEmulation module implements Near-Field Communication (NFC) card emulation. The **cardEmulation** module implements Near-Field Communication (NFC) card emulation.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean ...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported. ...@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.| | boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.|
## HceService ## HceService<sup>8+</sup>
Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance. Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance.
### startHCE ### startHCE<sup>8+</sup>
startHCE(aidList: string[]): boolean startHCE(aidList: string[]): boolean
...@@ -39,7 +39,7 @@ Starts HCE. ...@@ -39,7 +39,7 @@ Starts HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -47,7 +47,7 @@ Starts HCE. ...@@ -47,7 +47,7 @@ Starts HCE.
| ------- | -------- | ---- | ----------------------- | | ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.| | aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.|
### stopHCE ### stopHCE<sup>8+</sup>
stopHCE(): boolean stopHCE(): boolean
...@@ -55,9 +55,9 @@ Stops HCE. ...@@ -55,9 +55,9 @@ Stops HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
### on ### on<sup>8+</sup>
on(type: "hceCmd", callback: AsyncCallback<number[]>): void; on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**.
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. | | type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).| | callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).|
### sendResponse ### sendResponse<sup>8+</sup>
sendResponse(responseApdu: number[]): void; sendResponse(responseApdu: number[]): void;
...@@ -82,7 +82,7 @@ Sends a response to the peer device. ...@@ -82,7 +82,7 @@ Sends a response to the peer device.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
......
# Active Tag # Active Tag
The **connectedTag** module provides methods for using active tags. You can use the APIs provided by this module to initialize the active tag chip and read and write active tags.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,9 +24,9 @@ Initializes the active tag chip. ...@@ -22,9 +24,9 @@ Initializes the active tag chip.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the initialization is successful; returns **false** otherwise. | | boolean | Returns **true** if the initialization is successful; returns **false** otherwise.|
## connectedTag.uninit ## connectedTag.uninit
...@@ -38,9 +40,9 @@ Uninitializes the active tag resources. ...@@ -38,9 +40,9 @@ Uninitializes the active tag resources.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.readNdefTag ## connectedTag.readNdefTag
...@@ -54,14 +56,14 @@ Reads the content of this active tag. This method uses a promise to return the r ...@@ -54,14 +56,14 @@ Reads the content of this active tag. This method uses a promise to return the r
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the content of the active tag. | | Promise&lt;string&gt; | Promise used to return the content of the active tag.|
- Example - Example
``` ```
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
connectedTag.readNdefTag().then(result => { connectedTag.readNdefTag().then(result => {
console.log("promise recv ndef response: " + result); console.log("promise recv ndef response: " + result);
}); });
...@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback ...@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the active tag content obtained. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | data | string | Yes| Data to write. The maximum length is 1024 bytes.|
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. This method returns no value. | | Promise&lt;void&gt; | Promise used to return the result. This method returns no value.|
- Example - Example
``` ```
...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result.
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
writeNdefTag(data: string, callback: AsyncCallback&lt;string&gt;): void writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
Writes data to this active tag. This method uses an asynchronous callback to return the result. Writes data to this active tag. This method uses an asynchronous callback to return the result.
...@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret ...@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | data | string | Yes| Data to write. The maximum length is 1024 bytes.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the operation result. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -151,7 +153,7 @@ Writes data to this active tag. This method uses an asynchronous callback to ret ...@@ -151,7 +153,7 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
console.error(`failed to write event because ${err.code}`); console.error(`failed to write event because ${err.code}`);
return; return;
} }
// Data is written to the tag. // Data is written to the tag.
console.log(`success to write event: ${value}`); console.log(`success to write event: ${value}`);
}); });
...@@ -168,16 +170,16 @@ Registers the NFC field strength state events. ...@@ -168,16 +170,16 @@ Registers the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | Yes | Callback invoked to return the field strength state. | | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the field strength state.|
- Enumerates the field strength states. - Enumerates the field strength states.
| **Value** | **Description** | | **Value**| **Description**|
| -------- | -------- | | -------- | -------- |
| 0 | Field off. | | 0 | Field off.|
| 1 | Field on. | | 1 | Field on.|
## connectedTag.off('notify') ## connectedTag.off('notify')
...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events. ...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | No | Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered. | | callback | Callback&lt;number&gt; | No| Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
- Example - Example
``` ```
...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events. ...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events.
console.info("nfc rf receive state: " + result); console.info("nfc rf receive state: " + result);
} }
// Register event notification // Register event notification.
connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
// Unregister event notification // Unregister event notification.
connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
``` ```
...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events. ...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events.
Enumerates the NFC states. Enumerates the NFC states.
| Name | Default Value | Description | **System capability**: SystemCapability.Communication.ConnectedTag
| -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field off. | | Name| Default Value| Description|
| NFC_RF_ENTER | 1 | Field on. | | -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field on.|
| NFC_RF_ENTER | 1 | Field on.|
# Emitter # Emitter
> **NOTE**<br> The **Emitter** module provides APIs for sending and processing in-process events, including the APIs for processing events that are subscribed to in persistent or one-shot manner, unsubscribing from events, and emitting events to the event queue.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. > The initial APIs of this module are supported since API version 7.
## Modules to Import ## Modules to Import
...@@ -17,12 +20,14 @@ None ...@@ -17,12 +20,14 @@ None
Enumerates the event emit priority levels. Enumerates the event emit priority levels.
| Name | Value | Description | **System capability**: SystemCapability.Notification.Emitter
| --------- | ---- | ------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Value | Description |
| HIGH | 1 | The event will be emitted before low-priority events.<br>**System capability**: SystemCapability.Notification.Emitter | | --------- | ---- | ------------------------------------------------- |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.<br>**System capability**: SystemCapability.Notification.Emitter | | IMMEDIATE | 0 | The event will be emitted immediately. |
| IDLE | 3 | The event will be emitted after all the other events.<br>**System capability**: SystemCapability.Notification.Emitter | | HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## emitter.on ## emitter.on
...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return ...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve ...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -88,9 +93,9 @@ Unsubscribes from an event. ...@@ -88,9 +93,9 @@ Unsubscribes from an event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------ | | ------- | ------ | ---- | ------ |
| eventId | number | Yes | Event ID. | | eventId | number | Yes | Event ID.|
**Example** **Example**
...@@ -108,10 +113,10 @@ Emits an event to the event queue. ...@@ -108,10 +113,10 @@ Emits an event to the event queue.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------- | ---- | -------------- | | ------ | ------------------------- | ---- | -------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to emit. | | event | [InnerEvent](#innerevent) | Yes | Event to emit. |
| data | [EventData](#eventdata) | No | Data carried by the event. | | data | [EventData](#eventdata) | No | Data carried by the event.|
**Example** **Example**
...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData); ...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData);
## InnerEvent ## InnerEvent
Describes an intra-process event. Describes an in-process event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Type | Readable| Writable| Description |
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event.<br>**System capability**: SystemCapability.Notification.Emitter | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData ## EventData
Describes the data passed in the event. Describes the data passed in the event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.<br>**System capability**: SystemCapability.Notification.Emitter | | Name| Type | Readable| Writable| Description |
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.|
# Input Method Framework # Input Method Framework
> **NOTE** The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more.
> **NOTE**
> >
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -8,14 +10,14 @@ ...@@ -8,14 +10,14 @@
## Modules to Import ## Modules to Import
``` ```
import inputMethod from '@ohos.inputMethod'; import inputMethod from '@ohos.inputmethod';
``` ```
## inputMethod<sup>8+</sup> ## inputMethod<sup>8+</sup>
Provides the constants. Provides the constants.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -26,7 +28,7 @@ Provides the constants. ...@@ -26,7 +28,7 @@ Provides the constants.
Describes the input method application attributes. Describes the input method application attributes.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -37,15 +39,15 @@ Describes the input method application attributes. ...@@ -37,15 +39,15 @@ Describes the input method application attributes.
getInputMethodController(): InputMethodController getInputMethodController(): InputMethodController
Obtains an [InputMethodController](#InputMethodController) instance. Obtains an **[InputMethodController](#inputmethodcontroller)** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ----------------------------------------- | ---------------------------- |
| [InputMethodController](#InputMethodController) | Returns the current **InputMethodController** instance.| | [InputMethodController](#inputmethodcontroller) | Returns the current **InputMethodController** instance.|
**Example** **Example**
...@@ -57,25 +59,74 @@ Obtains an [InputMethodController](#InputMethodController) instance. ...@@ -57,25 +59,74 @@ Obtains an [InputMethodController](#InputMethodController) instance.
getInputMethodSetting(): InputMethodSetting getInputMethodSetting(): InputMethodSetting
Obtains an [InputMethodSetting](#InputMethodSetting) instance. Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | ---------------------------- | | ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#InputMethodSetting) | Returns the current **InputMethodSetting** instance.| | [InputMethodSetting](#inputmethodsetting8) | Returns the current **InputMethodSetting** instance.|
**Example** **Example**
```js ```js
var InputMethodSetting = inputMethod.getInputMethodSetting(); var InputMethodSetting = inputMethod.getInputMethodSetting();
``` ```
## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolean&gt;): void;
Switches to another input method. This API uses an asynchronous callback to return the result. This API can be used only in the stage model.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the execution result. |
**Example**
```js
inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => {
prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200});
});
```
## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt;
Switches to another input method. This API uses a promise to return the result. This API can be used only in the stage model.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
**Return value**
| Type | Description |
| ----------------------------------------- | ---------------------------- |
| Promise\<boolean> | Promise used to return the execution result. |
**Example**
```js
inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => {
prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200});
});
```
## InputMethodController ## InputMethodController
In the following API examples, you must first use [getInputMethodController](#getInputMethodController) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use **[getInputMethodController](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance.
### stopInput ### stopInput
...@@ -83,7 +134,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -83,7 +134,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
Hides the keyboard. This API uses an asynchronous callback to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -105,13 +156,13 @@ stopInput(): Promise&lt;boolean&gt; ...@@ -105,13 +156,13 @@ stopInput(): Promise&lt;boolean&gt;
Hides the keyboard. This API uses an asynchronous callback to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the keyboard is successfully hidden.| | Promise&lt;boolean&gt; | Promise used to return whether the keyboard is successfully hidden. |
**Example** **Example**
...@@ -123,7 +174,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -123,7 +174,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
## InputMethodSetting<sup>8+</sup> ## InputMethodSetting<sup>8+</sup>
In the following API examples, you must first use [getInputMethodSetting](#getInputMethodSetting) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use **[getInputMethodSetting](#inputmethodgetinputmethodsetting8)** to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance.
### listInputMethod ### listInputMethod
...@@ -131,13 +182,12 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -131,13 +182,12 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. Obtains the list of installed input methods. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------- | ---- | ---------------------- | | -------- | -------------------------------------------------- | ---- | ---------------------- |
| callback | Array<[InputMethodProperty](#InputMethodProperty)> | Yes | Callback used to return the list of installed input methods.| | callback | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return the list of installed input methods.|
**Example** **Example**
...@@ -156,13 +206,12 @@ listInputMethod(): Array&lt;InputMethodProperty&gt; ...@@ -156,13 +206,12 @@ listInputMethod(): Array&lt;InputMethodProperty&gt;
Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. Obtains the list of installed input methods. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ---------------------- | | ----------------------------------------------------------- | ---------------------- |
| Promise<Array<[InputMethodProperty](#InputMethodProperty)>> | Promise used to return the list of installed input methods.| | Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods. |
**Example** **Example**
...@@ -180,15 +229,16 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -180,15 +229,16 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.|
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod(()=>{ InputMethodSetting.displayOptionalInputMethod(()=>{
console.info('displayOptionalInputMethod is called'); console.info('displayOptionalInputMethod is called');
...@@ -197,20 +247,20 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ...@@ -197,20 +247,20 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono
### displayOptionalInputMethod ### displayOptionalInputMethod
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.| | Promise&lt;void&gt; | Promise used to return the execution result. |
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod(); InputMethodSetting.displayOptionalInputMethod();
``` ```
\ No newline at end of file
# Standard NFC # Standard NFC
Implements Near-Field Communication (NFC). The **nfcController** module implements Near-Field Communication (NFC).
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean ...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean
Checks whether NFC is available. Checks whether NFC is available.
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
...@@ -34,7 +36,7 @@ Opens NFC. ...@@ -34,7 +36,7 @@ Opens NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -50,7 +52,7 @@ Closes NFC. ...@@ -50,7 +52,7 @@ Closes NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -64,7 +66,7 @@ isNfcOpen(): boolean ...@@ -64,7 +66,7 @@ isNfcOpen(): boolean
Checks whether NFC is open. Checks whether NFC is open.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -78,7 +80,7 @@ getNfcState(): NfcState ...@@ -78,7 +80,7 @@ getNfcState(): NfcState
Obtains the NFC state. Obtains the NFC state.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void ...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void
Subscribes to NFC state changes. Subscribes to NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void ...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void
Unsubscribes from the NFC state changes. Unsubscribes from the NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes. ...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes.
Enumerates the NFC states. Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Default Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | Off| | STATE_OFF | 1 | Off|
......
# Standard NFC Tag # Standard NFC Tag
Manages Near-Field Communication (NFC) tags. The **nfcTag** module provides methods for managing Near-Field Communication (NFC) tags.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags. ...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags.
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
``` ```
## tag.getNfcATag ## tag.getNfcATag
getNfcATag(tagInfo: TagInfo): NfcATag getNfcATag(tagInfo: TagInfo): NfcATag
...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC- ...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC- ...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC- ...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC- ...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| NfcVTag | **NfcVTag** object obtained.| | NfcVTag | **NfcVTag** object obtained.|
# Button # Button
The **\<Button>** component can be used to create different types of buttons.
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Button&gt;** component represents a component that can trigger actions.
## Required Permissions ## Required Permissions
None None
...@@ -30,15 +29,15 @@ Supported ...@@ -30,15 +29,15 @@ Supported
| stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. | | stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. |
- Button(label?: string, options?: { type?: ButtonType, stateEffect?: boolean }) - Button(label?: ResourceStr, options?: { type?: ButtonType, stateEffect?: boolean })
Creates a button component based on text content. In this case, the **&lt;Button&gt;** component cannot contain child components. Creates a button component based on text content. In this case, the **\<Button>** component cannot contain child components.
**Table 2** value parameters **Table 2** Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| label | string | No | - | Button text. | | label | [ResourceStr](../../ui/ts-types.md) | No | - | Button text. |
| options | Object | No | - | For details, see the **options** parameters. | | options | Object | No | - | For details, see the **options** parameters. |
...@@ -54,8 +53,8 @@ Supported ...@@ -54,8 +53,8 @@ Supported
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| Capsule | Capsule-type button (the round corner is half of the height by default). | | Capsule | Capsule-type button (the round corner is half of the height by default). |
| Circle | Circle button. | | Circle | Circle button. |
| Normal | Normal button (without rounded corners by default). | | Normal | Normal button (without rounded corners by default). |
> **NOTE** > **NOTE**
> - The rounded corner of a button is set by using [Border](ts-universal-attributes-border.md). (The rounded corner cannot be set by using a border API.) > - The rounded corner of a button is set by using [Border](ts-universal-attributes-border.md). (The rounded corner cannot be set by using a border API.)
...@@ -67,7 +66,8 @@ Supported ...@@ -67,7 +66,8 @@ Supported
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct ButtonExample { struct ButtonExample {
...@@ -78,6 +78,7 @@ struct ButtonExample { ...@@ -78,6 +78,7 @@ struct ButtonExample {
Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90) Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Normal, stateEffect: true }) { Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() { Row() {
// You are advised to reference an image by using $r to create a Resource object.
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 }) Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 }) Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center) }.alignItems(VerticalAlign.Center)
......
...@@ -91,7 +91,11 @@ struct ProgressExample { ...@@ -91,7 +91,11 @@ struct ProgressExample {
Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50) Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100).height(50) Progress({ value: 20, total: 150, type: ProgressType.Capsule })
.color(Color.Grey)
.value(50)
.width(100)
.height(50)
} }
}.width('100%').margin({ top: 30 }) }.width('100%').margin({ top: 30 })
} }
......
# Slider # Slider
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Slider&gt;** component is used to quickly adjust settings, such as the volume and brightness. The *\<Slider>** component is used to quickly adjust settings, such as the volume and brightness.
## Required Permissions ## Required Permissions
...@@ -15,7 +16,7 @@ None ...@@ -15,7 +16,7 @@ None
## Child Components ## Child Components
None Not supported
## APIs ## APIs
...@@ -44,12 +45,12 @@ Slider(value:{value?: number, min?: number, max?: number, step?: number, style?: ...@@ -44,12 +45,12 @@ Slider(value:{value?: number, min?: number, max?: number, step?: number, style?:
Touch target configuration is not supported. Touch target configuration is not supported.
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| ------------- | ------- | ------------- | -------------------------------------------------------------------- | | ------------- | ------- | ------------- | ---------------------------------------- |
| blockColor | Color | - | Color of the slider. | | blockColor | Color | - | Color of the slider. |
| trackColor | Color | - | Background color of the slider. | | trackColor | Color | - | Background color of the slider. |
| selectedColor | Color | - | Color of the slider rail that has been slid. | | selectedColor | Color | - | Color of the slider rail that has been slid. |
| showSteps | boolean | false | Whether to display the current step. | | showSteps | boolean | false | Whether to display the current step. |
| showTips | boolean | false | Whether to display a bubble to indicate the percentage when sliding. | | showTips | boolean | false | Whether to display a bubble to indicate the percentage when sliding. |
...@@ -62,17 +63,18 @@ Among all the universal events, only **OnAppear** and **OnDisAppear** are suppor ...@@ -62,17 +63,18 @@ Among all the universal events, only **OnAppear** and **OnDisAppear** are suppor
| onChange(callback: (value: number, mode: SliderChangeMode) =&gt; void) | Callback invoked when the slider slides.<br/>**value**: current progress.<br/>**mode**: dragging state. | | onChange(callback: (value: number, mode: SliderChangeMode) =&gt; void) | Callback invoked when the slider slides.<br/>**value**: current progress.<br/>**mode**: dragging state. |
- SliderChangeMode enums - SliderChangeMode enums
| Name | Description | | Name | Value | Description |
| ------ | ----------------------------------- | | ------ | ----- | ----------------------------------- |
| Begin | The user starts to drag the slider. | | Begin | 0 | The user starts to drag the slider. |
| Moving | The user is dragging the slider. | | Moving | 1 | The user is dragging the slider. |
| End | The user stops dragging the slider. | | End | 2 | The user stops dragging the slider. |
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct SliderExample { struct SliderExample {
......
# CanvasGradient # CanvasGradient
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -17,18 +18,18 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse ...@@ -17,18 +18,18 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| offset | number | Yes | 0 | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. | | offset | number | Yes | 0 | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. |
| color | string | Yes | 'ffffff' | Gradient color to set. | | color | string | Yes | '#ffffff'| Gradient color to set. |
- Example - Example
```ts
``` // xxx.ets
@Entry @Entry
@Component @Component
struct Page45 { struct Page45 {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context) Canvas(this.context)
...@@ -37,9 +38,9 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse ...@@ -37,9 +38,9 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var grad = this.context.createLinearGradient(50,0, 300,100) var grad = this.context.createLinearGradient(50,0, 300,100)
this.grad.addColorStop(0.0, 'red') grad.addColorStop(0.0, 'red')
this.grad.addColorStop(0.5, 'white') grad.addColorStop(0.5, 'white')
this.grad.addColorStop(1.0, 'green') grad.addColorStop(1.0, 'green')
this.context.fillStyle = grad this.context.fillStyle = grad
this.context.fillRect(0, 0, 500, 500) this.context.fillRect(0, 0, 500, 500)
}) })
......
# Button
The **\<Button>** component can be used to create different types of buttons.
> **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
None
## Child Components
Supported
## APIs
- Button(options?: {type?: ButtonType, stateEffect?: boolean})
**Table 1** options parameters
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| type | ButtonType | No | Capsule | Button type. |
| stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. |
- Button(label?: ResourceStr, options?: { type?: ButtonType, stateEffect?: boolean })
Creates a button component based on text content. In this case, the **\<Button>** component cannot contain child components.
**Table 2** Parameters
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| label | [ResourceStr](../../ui/ts-types.md) | No | - | Button text. |
| options | Object | No | - | For details, see the **options** parameters. |
## Attributes
| Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- |
| type | ButtonType | Capsule | Button type. |
| stateEffect | boolean | true | Whether to enable the state switchover effect. When the state is set to **false**, the state switchover effect is disabled. |
**ButtonType** enums
| Name | Description |
| -------- | -------- |
| Capsule | Capsule-type button (the round corner is half of the height by default). |
| Circle | Circle button. |
| Normal | Normal button (without rounded corners by default). |
> **NOTE**
> - The rounded corner of a button is set by using [Border](ts-universal-attributes-border.md). (The rounded corner cannot be set by using a border API.)
> - When the button type is **Capsule**, the **borderRadius** settings do not take effect, and the rounded corner of the button is always half of the button height.
> - When the button type is **Circle**, the value of **borderRadius** is used as the button radius. If **borderRadius** is not set, the button radius is half of the width or height, whichever is smaller.
> - The button text is set using the [common text style](ts-universal-attributes-text-style.md).
## Example
```ts
// xxx.ets
@Entry
@Component
struct ButtonExample {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Text('Common button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() {
// You are advised to reference an image by using $r to create a Resource object.
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center)
}.borderRadius(8).backgroundColor(0x317aff).width(90)
Button('Disable', { type: ButtonType.Normal, stateEffect: false }).opacity(0.5)
.borderRadius(8).backgroundColor(0x317aff).width(90)
}
Text('Capsule button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Ok', { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Capsule, stateEffect: true }) {
Row() {
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center).width(90)
}.backgroundColor(0x317aff)
.onClick((event: ClickEvent) => {
AlertDialog.show({ message: 'The login is successful' })
})
Button('Disable', { type: ButtonType.Capsule, stateEffect: false }).opacity(0.5)
.backgroundColor(0x317aff).width(90)
}
Text('Circle button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) {
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r('app.media.ic_public_app_filled')).width(20).height(20)
}.width(55).height(55).backgroundColor(0x317aff)
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r('app.media.ic_public_delete_filled')).width(30).height(30)
}.width(55).height(55).margin({ left: 20 }).backgroundColor(0xF55A42)
}
}.height(400).padding({ left: 35, right: 35, top: 35 })
}
}
```
![en-us_image_0000001257138341](figures/en-us_image_0000001257138341.gif)
...@@ -29,9 +29,9 @@ Ability框架在API 8及更早版本使用FA模型。FA模型中Ability分为Pag ...@@ -29,9 +29,9 @@ Ability框架在API 8及更早版本使用FA模型。FA模型中Ability分为Pag
## 相关实例 ## 相关实例
针对Ability开发,有以下相关实例可供参考: 针对Ability开发,有以下相关实例可供参考:
- [`DistributeCalc`:分布式计算器(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Preset/DistributeCalc) - [`DistributedCalc`:分布式计算器(JS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/DistributeCalc)
- [`DistributeGraffiti`:分布式涂鸦(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DistributedGraffiti) - [`DistributedCalc`:分布式计算器(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Preset/DistributeCalc)
- [`DistributeGraffiti`:分布式涂鸦(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DistributedGraffiti)
- [分布式调度启动远程FA(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteStartFA) - [分布式调度启动远程FA(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteStartFA)
- [分布式新闻客户端(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/NewsDemo) - [分布式新闻客户端(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/NewsDemo)
- [分布式手写板(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts) - [分布式手写板(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts)
......
...@@ -311,4 +311,4 @@ URI示例: ...@@ -311,4 +311,4 @@ URI示例:
针对DataAbility开发,有以下相关实例可供参考: 针对DataAbility开发,有以下相关实例可供参考:
- [`DataAbility`:DataAbility的创建与访问(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DataAbility) - [`DataAbility`:DataAbility的创建与访问(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DataAbility)
...@@ -350,5 +350,5 @@ onUpdate(formId) { ...@@ -350,5 +350,5 @@ onUpdate(formId) {
## 相关实例 ## 相关实例
针对FA模型卡片提供方的开发,有以下相关实例可供参考: 针对FA模型卡片提供方的开发,有以下相关实例可供参考:
- [`FormAbility`:FA模型卡片(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormAbility) - [`FormAbility`:FA模型卡片(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormAbility)
- [`FormLauncher`:卡片使用方(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormLauncher) - [`FormLauncher`:卡片使用方(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormLauncher)
\ No newline at end of file \ No newline at end of file
...@@ -227,4 +227,4 @@ export default { ...@@ -227,4 +227,4 @@ export default {
针对PageAbility开发,有以下相关实例可供参考: 针对PageAbility开发,有以下相关实例可供参考:
- [`DMS`:分布式Demo(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DMS) - [`DMS`:分布式Demo(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DMS)
\ No newline at end of file \ No newline at end of file
...@@ -430,5 +430,5 @@ export default { ...@@ -430,5 +430,5 @@ export default {
## 相关实例 ## 相关实例
针对ServiceAbility开发,有以下相关实例可供参考: 针对ServiceAbility开发,有以下相关实例可供参考:
- [`ServiceAbility`:ServiceAbility的创建与使用(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceAbility) - [`ServiceAbility`:ServiceAbility的创建与使用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/ServiceAbility)
- [`DMS`:分布式Demo(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DMS) - [`DMS`:分布式Demo(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DMS)
...@@ -320,4 +320,4 @@ struct Index { ...@@ -320,4 +320,4 @@ struct Index {
## 相关实例 ## 相关实例
针对Stage模型Ability开发,有以下相关示例可供参考: 针对Stage模型Ability开发,有以下相关示例可供参考:
- [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility) - [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/StageCallAbility)
...@@ -97,4 +97,4 @@ ...@@ -97,4 +97,4 @@
![stageprocessmodel](figures/stageprocessmodel.png) ![stageprocessmodel](figures/stageprocessmodel.png)
## 相关实例 ## 相关实例
针对Stage模型下的Ability开发,有以下相关实例可供参考: 针对Stage模型下的Ability开发,有以下相关实例可供参考:
- [`MissionManager`:系统任务管理(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/MissionManager) - [`MissionManager`:系统任务管理(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/MissionManager)
...@@ -250,4 +250,4 @@ try { ...@@ -250,4 +250,4 @@ try {
## 相关实例 ## 相关实例
针对Stage模型本地Call功能开发,有以下相关实例可供参考: 针对Stage模型本地Call功能开发,有以下相关实例可供参考:
- [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility) - [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/StageCallAbility)
...@@ -361,4 +361,4 @@ onUpdate(formId) { ...@@ -361,4 +361,4 @@ onUpdate(formId) {
## 相关实例 ## 相关实例
针对Stage模型卡片提供方的开发,有以下相关实例可供参考: 针对Stage模型卡片提供方的开发,有以下相关实例可供参考:
- [`FormExtAbility`:Stage模型卡片(eTS JS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormExtAbility) - [`FormExtAbility`:Stage模型卡片(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormExtAbility)
\ No newline at end of file \ No newline at end of file
...@@ -75,4 +75,4 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。 ...@@ -75,4 +75,4 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。
## 相关实例 ## 相关实例
针对ServiceExtensionAbility开发,有以下相关实例可供参考: 针对ServiceExtensionAbility开发,有以下相关实例可供参考:
- [`ServiceExtAbility`:StageExtAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceExtAbility) - [`ServiceExtAbility`:StageExtAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/ServiceExtAbility)
...@@ -74,5 +74,5 @@ httpRequest.request( ...@@ -74,5 +74,5 @@ httpRequest.request(
## 相关实例 ## 相关实例
针对HTTP数据请求,有以下相关实例可供参考: 针对HTTP数据请求,有以下相关实例可供参考:
- [`Http`:数据请求(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Network/Http) - [`Http:`数据请求(eTS)(API9))](https://gitee.com/openharmony/applications_app_samples/tree/master/Network/Http)
- [使用HTTP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH) - [使用HTTP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH)
\ No newline at end of file
...@@ -360,5 +360,5 @@ ...@@ -360,5 +360,5 @@
## 相关实例 ## 相关实例
针对关系型数据库开发,有以下相关实例可供参考: 针对关系型数据库开发,有以下相关实例可供参考:
- [`DistributedRdb`:分布式关系型数据库(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedRdb) - [`DistributedRdb`:分布式关系型数据库(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DistributedRdb)
- [关系型数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData) - [关系型数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册