Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query : How to change background color or set background drawable to a specific TAG for onClick event #54

Closed
pravingaikwad07 opened this issue May 30, 2017 · 7 comments

Comments

@pravingaikwad07
Copy link

I want to set different drawable/color to a specific tag on onClick on that tag. Pls suggest me the way to do so.

Below is my code:

xml:

      app:container_border_color="@android:color/transparent"
        app:container_background_color="@android:color/transparent"
        app:tag_background_color="@android:color/transparent"
        app:tag_border_color="@color/deep_rose_two"
        app:container_enable_drag="false"
        app:horizontal_interval="10dp"
        app:tag_clickable="true"
        app:tag_text_color="@color/black"
        app:tag_text_size="12sp"
        app:tag_theme="none"
        app:vertical_interval="10dp"

Code:

     for (int i = 0; i < 10; i++) {
           tags.add("Tag " + (i + 1));
       }
       List<int[]> colors = new ArrayList<int[]>();
       tagContainer.setTags(tags, colors);
       tagContainer.setOnTagClickListener(new TagView.OnTagClickListener() {
        
     @Override
           public void onTagClick(int position, String text) {
             Log.d(TAG, "onTagClick: position: "+position+", text: "+text);
         tagContainer.setTagBackgroundColor(getResources().getColor(R.color.deep_rose_two));
               tagContainer.setTagTextColor(getResources().getColor(R.color.white));
        }

        @Override
           public void onTagLongClick(final int position, String text) {
          }

           @Override
           public void onTagCrossClick(int position) {
          }
       });
@whilu
Copy link
Owner

whilu commented May 30, 2017

@pravingaikwad123
You can change specify TagView's color like this:

mTagcontainerLayout.setOnTagClickListener(new TagView.OnTagClickListener() {

    @Override
    public void onTagClick(int position, String text) {
        TagView tagView = mTagcontainerLayout.getTagView(position);
        tagView.setTagTextColor(Color.GRAY);
        tagView.setTagBackgroundColor(Color.YELLOW);
        tagView.setTagBorderColor(Color.BLACK);
        tagView.postInvalidate();
    }

    @Override
    public void onTagLongClick(int position, String text) {}

    @Override
    public void onTagCrossClick(int position) {}
});

@pravingaikwad07
Copy link
Author

Thanks alot. It worked.

@pravingaikwad07
Copy link
Author

pravingaikwad07 commented May 31, 2017

@whilu : Please suggest me a way to set default background drawable to all the tags in the tagcontainer. Can I do this within xml itself ? What is the attribute for it ? Or do I need to use "for" loopand getAllTagViews from container and then set background (drawable) to each view...

I want to do something like this : My present code resultant -->
screen shot 2017-05-31 at 11 12 39 am (In screenshot my selected drawable is not getting matched with default style of tagview. So i want to set default drawable with white background and selected drawable with gradient one drawable.

So finally I want like this: ->>
screen shot 2017-05-31 at 11 14 15 am

@whilu
Copy link
Owner

whilu commented May 31, 2017

@pravingaikwad123
There is no attribute for default background drawable in layout(This is a good feature, I will add this in next version). If you want to set background drawable, you need to loop all TagView and set background drawable one by one(UI thread).

for (int i = 0; i < mTagContainerLayout.getTags().size(); ++i){
    TagView tagView = mTagContainerLayout.getTagView(i);
    tagView.setBackgroundResource(R.drawable.xxx);
    tagView.postInvalidate();
}

@pravingaikwad07
Copy link
Author

@whilu .. Thanks for the answer.

Can yougive me a rough idea uptil when you'll release updated version ? So, that I can keep my work on hold accordingly.

@whilu
Copy link
Owner

whilu commented Jun 1, 2017 via email

@whilu
Copy link
Owner

whilu commented Jun 1, 2017

@pravingaikwad123

The latest version v1.1.4 has supported default background for TagView.

How to set(two ways):

  • Set attribute tag_background in layout file
  • Before you set tags, add this code:
mTagContainerLayout.setTagBackgroundResource(R.drawable.xxx);

@whilu whilu closed this as completed Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants