1 Star 0 Fork 1

Archermind-TI / nachos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

nachos

Introduce

Nachos is a library for APP that provides a custom TextView allowing users to enter text and create material chips in the text field.

Effect demonstration

效果演示

Installation

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"
}

Usage

Basic Usage

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"/>

Customizing the UI

NachoTextView offers several custom attributes that allow you to control the appearance of the chips it creates:

  • chipHorizontalSpacing - The horizontal space between chips
  • chipBackground - The background color of the chip, can be a ColorStateList to change color when the chip is clicked
  • chipCornerRadius - The corner radius of the chip background
  • chipTextColor - The color of the chip text
  • chipTextSize - The font size of the chip text
  • chipHeight - The height of a single chip
  • chipVerticalSpacing - 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>

Listening for when a Chip is Touched

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) {
                
            }
        });

Reading the Values of the Chips

NachoTextView exposes several methods to read the contents of the text view:

  • getAllChips()
    • Returns the actual Chip objects contained in the text view
    • Chip is an interface that represents a chip and declares methods to access the text (getText()), data (getData()), and ui attributes of the chip
  • getChipValues()
    • Returns a List of the string values of all the chips in the text
  • getTokenValues()
    • Returns a List of the string values of all the tokens (unchipped text) in the text
  • getChipAndTokenValues()
    • Returns a combination of the chip values and token values in the text.
    • Effectively a concatenation of the previous two methods (getChipValues() and getTokenValues())

Using a Custom UI Element for the Chips

    nachoTextView.setElement(ResourceTable.Media_fork);

Click Enter to hide textFiled

Click Enter to hide textField

效果演示

Click Enter to show textFiled

Click any chips to show textField

效果演示

License

Nachos is released under the Apache License, Version 2.0. See LICENSE for details.

Copyright 2016 Hootsuite Media, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/archermind-ti/nachos.git
git@gitee.com:archermind-ti/nachos.git
archermind-ti
nachos
nachos
master

搜索帮助