Kongzue StackLabel

Kongzue StackLabel is a StackLabel component, suitable for quick StackLabel scenarios, such as “search history”, “guess what you like”, etc.

Github

Github.com/kongzue/Sta…




The preview figure is as follows:

Demo download address: fir. Im/StackLabel

advantage

  • Easy to use and quick to create, meeting most stack label application scenarios.

Method of use

  1. Import from Maven repository or jCenter:
< the dependency > < groupId > com. Kongzue. Stacklabel < / groupId > < artifactId > stacklabelview < / artifactId > < version > 1.1.0 < / version > <type>pom</type>
</dependency>
Copy the code

Gradle: Add a reference to dependencies{}

implementation 'com. Kongzue. Stacklabel: stacklabelview: 1.1.0'
Copy the code
  1. Create from an XML layout file:
<com.kongzue.stacklabelview.StackLabel xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stackLabelView"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    app:textColor="#e6000000"
    app:itemMargin="4dp"
    app:paddingHorizontal="12dp"
    app:paddingVertical="8dp"
    app:deleteButton="false"
    app:textSize="12dp"
    />
Copy the code

The supported custom attributes are explained as follows:

field meaning type
app:textColor Tag text color ColorInt
app:itemMargin Label margin Int (pixels)
app:paddingHorizontal Distance between left and right inside the label Int (pixels)
app:paddingVertical Upper and lower spacing inside the label Int (pixels)
app:deleteButton Whether the delete button is displayed by default boolean
app:textSize Tag text size Int (pixels)
app:deleteButtonImage Delete icon ResId (resource ID, such as @mipmap/img_delete)
app:labelBackground The Label background ResId (resource ID, such as @mipmap/img_delete)
  1. Add content:

StackLabel currently supports only plain text label representation. You can add String String text to display as a List set to StackLabel to render the desired content, as shown in the following example:

labels = new ArrayList<>();
labels.add("Where do I charge my bill?");
labels.add("Write a letter to the future.");
labels.add("Password keyboard");
labels.add("Raise your hand and wake up.");
labels.add("Cutisan");
labels.add("Remember - Focus on creation.");
labels.add("I don't know who I am.");
labels.add("Bam bam bam!");
labels.add("Android");
labels.add("Development");
stackLabelView.setLabels(labels);
Copy the code

To implement TAB clicking, you need to set the click listener:

stackLabelView.setOnLabelClickListener(new OnLabelClickListener() {
    @Override
    public void onClick(int index, View v, String s) {
        Toast.makeText(MainActivity.this, "Click:"+ s, Toast.LENGTH_SHORT).show(); }});Copy the code

You can use setDeleteButton(Boolean) in code to switch StackLabel deletion mode on or off:

stackLabelView.setDeleteButton(ture);
Copy the code

When DeleteButton is on, clicking on any label deletes the label:

stackLabelView.setOnLabelClickListener(new OnLabelClickListener() {
    @Override
    public void onClick(int index, View v, String s) {
        if(stackLabelView isDeleteButton ()) {/ / delete and reset the tag labels. Remove (index); stackLabelView.setLabels(labels); }else {
            Toast.makeText(MainActivity.this, "Click:"+ s, Toast.LENGTH_SHORT).show(); }}});Copy the code

That’s the basic usage flow for StackLabel.

Open source licenses

Copyright Kongzue StackLabel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except inThe 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 toin 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.
Copy the code

Update log

V1.1.0:

  • New properties deleteButtonImage and labelBackground set properties;

V1.0:

  • New release;