Nachos is a library for APP that provides a custom TextView allowing users to enter text and create material chips in the text field.
Packages up your library into a har, and add the har to the directory entry libs,
Add implementation codes to directory entry/gradle:
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
Add this line to your module level build.gradle:
allprojects{
repositories{
mavenCentral()
}
}
dependencies {
implementation "com.gitee.archermind-ti:nachos:1.0.3"
}
Include a NachoTextView
in your xml layout as follows:
<com.hootsuite.nachos.NachoTextView
ohos:id="$+id:id_first_nachoTextView"
ohos:height="match_content"
ohos:width="match_parent"
ohos:left_margin="10vp"
ohos:right_margin="20vp"/>
NachoTextView offers several custom attributes that allow you to control the appearance of the chips it creates:
chipHorizontalSpacing
- The horizontal space between chipschipBackground
- The background color of the chip, can be a ColorStateList to change color when the chip is clickedchipCornerRadius
- The corner radius of the chip backgroundchipTextColor
- The color of the chip textchipTextSize
- The font size of the chip textchipHeight
- The height of a single chipchipVerticalSpacing
- The vertical space between chips on consecutive lines.Note: chipVerticalSpacing
can only be used if chipHeight
is also set
Use these attributes as follows:
<com.hootsuite.nachos.NachoTextView
ohos:id="$+id:id_first_nachoTextView"
ohos:width="match_parent"
ohos:height="wrap_content"
app:chipHorizontalSpacing="2dp"
app:chipBackground="@color/chip_background"
app:chipTextColor="@color/cheddar"
app:chipTextSize="16dp"
app:chipHeight="30dp"
app:chipVerticalSpacing="3dp"/>
Don't forget to declare the app namespace on your root layout element:
<StackLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
xmlns:app="http://schemas.huawei.com/res/ohos-auto"
ohos:id="$+id:root"
ohos:height="match_content"
ohos:width="match_parent">
</StackLayout>
If you want to perform any custom actions when a chip is clicked you can attach an OnChipClickListener
to the NachoTextView:
nachosTextView.setOnChipClickListener(new OnChipClickListener() {
@Override
public void onChipClickListener(Component component) {
}
});
NachoTextView exposes several methods to read the contents of the text view:
getAllChips()
Chip
objects contained in the text viewChip
is an interface that represents a chip and declares methods to access the text (getText()
), data (getData()
), and ui attributes of the chipgetChipValues()
getTokenValues()
getChipAndTokenValues()
getChipValues()
and getTokenValues()
) nachoTextView.setElement(ResourceTable.Media_fork);
Click Enter to hide textField
Click any chips to show textField
Nachos is released under the Apache License, Version 2.0. See LICENSE for details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。