Giter Site home page Giter Site logo

bryanx / themed-toggle-button-group Goto Github PK

View Code? Open in Web Editor NEW
748.0 748.0 45.0 6.2 MB

Customisable toggle buttons inside a FlexboxLayout.

License: MIT License

Kotlin 100.00%
android android-development android-library android-ui kotlin kotlin-android kotlin-library toggle-button-group toggle-buttons

themed-toggle-button-group's People

Contributors

amankumar367 avatar bryanx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

themed-toggle-button-group's Issues

Button's strange size

The code

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="vertical">

                <nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup
                    android:id="@+id/days"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:justifyContent="center"> <!-- this attribute is from the underlying FlexboxLayout -->

                    <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                        android:id="@+id/monday"
                        android:layout_width="wrap_content"
                        android:layout_height="38dp"
                        app:toggle_text="Lunedì"
                        app:toggle_selectedBackgroundColor="@color/primary_color"/>

                    <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                        android:id="@+id/tuesday"
                        android:layout_width="wrap_content"
                        android:layout_height="38dp"
                        app:toggle_text="Martedì"
                        app:toggle_selectedBackgroundColor="@color/primary_color"/>
                    />

                    <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                        android:id="@+id/wednesday"
                        android:layout_width="wrap_content"
                        android:layout_height="38dp"
                        app:toggle_text="Mercoledì"
                        app:toggle_selectedBackgroundColor="@color/primary_color"/>
                    />

                    <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                        android:id="@+id/btn2"
                        android:layout_width="wrap_content"
                        android:layout_height="38dp"
                        app:toggle_text="Giovedì"
                        app:toggle_selectedBackgroundColor="@color/primary_color"/>
                    />

                  
                </nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup>
             </LinearLayout>

Screenshots
bug1
Only when I select a button it shows correctly.
bug2

Add support for borders.

At the moment the button's don't support borders yet. It would be nice if they can be styled programmatically, have different colors when they are selected/deselected. This shouldn't be too hard to implement. It can be added to RoundedCornerLayout.kt

wanted then to be in a single line

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

image

Create a separate version for Jetpack Compose

At some point I would like to port this library to Jetpack Compose.

Some points to consider:

  • Find a replacement method for laying out the container other than FlexboxLayout for Compose.
  • Maybe expose segmented builders for the attributes.

PR's are welcome.

Does it work with recyclerview?

I tried creating an adapter and using FlexboxLayoutManager but it's not working, is there anyway to achieve multi selection with recyclerview?

Thanks.

Set selected button colour not working

setSelectedBgColor() shows incorrect color. For some reason the colors always seem to be different shades of purple, whereby my intended color is blended with the default color (denim). Here is my code:

Screenshot 2021-01-02 at 6 17 29 PM

Customize font family

An XML attribute to set the font resource would be great. Programmatic way to do it as well would be a bonus.

Bug: button doesn't change with quick selection

I have two buttons with single selection. When I click on an unselected button, and then quickly select the first again, while the animation is still running, the first button does not change the background and color of the text. Thus, both buttons look unselected, although one of them is actually selected.

Add Font family

Hello, It's a very amazing library
But I don’t know how to find the font path to add here " btn.setFontFamily() "
here in my font file
image
how can I find his path
Thanks in advance for help.

Last line disappears when text size of specific item is long

Hi. I am going to create a woman health project using your library but I encountered an issue.
When I try to create multiple lines of different sizes of items, the last line disappears.
My code looks like this:

<style name="SymptomsItemStyle">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginTop">5dp</item>
        <item name="android:layout_marginBottom">5dp</item>
        <item name="toggle_paddingTop">10dp</item>
        <item name="toggle_paddingBottom">10dp</item>
        <item name="layout_flexGrow">1</item>
    </style>

<nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:toggle_selectableAmount="9"
            app:toggle_requiredAmount="0"
            app:toggle_horizontalSpacing="0dp"
            app:flexWrap="wrap"
            >

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:toggle_text="@string/intensity_light" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                app:toggle_text="asdfasdfa" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:toggle_text="@string/intensity_severe" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:layout_wrapBefore="true"
                app:toggle_text="@string/intensity_light" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                app:toggle_text="@string/intensity_average" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:toggle_text="@string/intensity_severe" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:layout_wrapBefore="true"
                app:toggle_text="@string/intensity_light" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                app:toggle_text="@string/intensity_average" />

            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                style="@style/SymptomsItemStyle"
                app:toggle_text="@string/intensity_severe" />

        </nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup>

issue

How can I fix this issue?
Hope to hearing from you soon.
Thanks.

How can I disable it?

mBinding.reviewResultToggle.isClickable = false
mBinding.reviewResultToggle.isActivated = false
mBinding.reviewResultToggle.isEnabled = false
mBinding.reviewResultToggle.isSelected = false
for (button in mBinding.reviewResultToggle.buttons) {
button.isClickable = false
button.isActivated = false
button.isEnabled = false
button.isSelected = false
}
Also not work.
Can I lock the change?

setOnClickListener getting callback twice

I have some requirements where some buttons will be disabled but onClick of that button show toast message.
When trying to add setOnClickListener on the disabled button, I was getting toast twice.

To Reproduce

val btn2 = ThemedButton(buttonGroup.context)
btn2.text = "Button 2"
btn2.isEnabled = false
buttonGroup.addView(btn2, ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT))


buttonGroup.buttons.forEach { button ->
      if (button.isEnabled.not()) {
            button.setOnClickListener { showToast("${btn2.text} clicked") }
      }
}

Make some Themed buttons enabled or disabled

First of all, thank you for this library. It's pretty useful 👍

Although, I found a need to have some buttons enabled/disabled. Since the clickEvent is handled in the group class, I had some issues blocking it. I guess a simple solution is to check in the addClickListeners method if the button is enabled or not.

My workaround looks something like this and it works fine:

@SuppressLint("ClickableViewAccessibility")
    private fun addClickListeners(btn: ThemedButton) {
        btn.cvCard.setOnTouchListener { _, event ->
            if (btn.isEnabled) {
                selectButtonWithAnimation(btn, event.x, event.y)
                if (event.action == MotionEvent.ACTION_UP) btn.performClick()
                event.action == MotionEvent.ACTION_UP
            } else false
        }
    }

Option to remove click button effect

Is your feature request related to a problem? Please describe.
When I select the other button in the group, my recyclerview will automatically reload data from server. I observed that the effect is played not very smoothly despite the fact that I run all my actions on Dispatchers.Default instead of on UI Thread. I can disable animation by given none to the group but when I click the button, it get smaller and after releasing the button it become the original size. It's there a way to disable this kine of behaviour (animation)?

Describe the solution you'd like
Given each ThemedToggleButton a aniamtion property

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Vertically align buttons

Is there any way to align buttons vertically inside "ThemedToggleButtonGroup" layout? I need to add 3 buttons of same width and height vertically.

I have Err (android.view.InflateException)

I have a problem to use it.

I added these dependencies in my app's build.gradle file:
dependencies {
implementation 'nl.bryanderidder:themed-toggle-button-group:1.3.1'
implementation 'com.google.android:flexbox:2.0.1'
}

But, When I use it, I got Err:(

Caused by: android.view.InflateException: Binary XML file line #221 in com.example.myvoice:layout/activity_voter_pollcreate: Binary XML file line #221 in com.example.myvoice:layout/activity_voter_pollcreate: Error inflating class nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup
Caused by: android.view.InflateException: Binary XML file line #221 in com.example.myvoice:layout/activity_voter_pollcreate: Error inflating class nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup

Please tell me What is wrong?

Request to made the button toggle-able

in multiple selection, after toggle once, it will be "true" always, if I click back on the same button, it should be change to "false" instead staying "true" forever

AAPT: error: attribute layout_flexShrink

Describe the bug
create horizontal layout
give me error like this
"AAPT: error: attribute layout_flexShrink"


<HorizontalScrollView
                        android:layout_marginTop="10dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fillViewport="true"
                        android:scrollbars="none">

                        <nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup
                            android:id="@+id/time"
                            android:layout_width="wrap_content"
                            android:layout_height="45dp">

                            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                                android:id="@+id/btnAll"
                                android:layout_width="wrap_content"
                                android:layout_height="38dp"
                                app:layout_flexShrink="0"
                                app:toggle_text="Semua" />

                            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                                android:id="@+id/btnHariini"
                                android:layout_width="wrap_content"
                                android:layout_height="38dp"
                                app:layout_flexShrink="0"
                                app:toggle_text="Hari Ini" />

                            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                                android:id="@+id/btnKemarin"
                                android:layout_width="wrap_content"
                                android:layout_height="38dp"
                                app:layout_flexShrink="0"
                                app:toggle_text="Kemain" />

                            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                                android:id="@+id/btnMinggu"
                                android:layout_width="wrap_content"
                                android:layout_height="38dp"
                                app:layout_flexShrink="0"
                                app:toggle_text="Minggu ini" />
                            <nl.bryanderidder.themedtogglebuttongroup.ThemedButton
                                android:id="@+id/btnBulan"
                                android:layout_width="wrap_content"
                                android:layout_height="38dp"
                                app:layout_flexShrink="0"
                                app:toggle_text="Bulan Ini" />
                        </nl.bryanderidder.themedtogglebuttongroup.ThemedToggleButtonGroup>
                    </HorizontalScrollView>

The IDE breaks when I add the selection listener codes

When I add selection listener codes to my Java class, the Android Studio IDE breaks. Autocomplete codes do not work and the above class icon "C" toggles. I can't write any code, it just gets better when I close the IDE and restart it, it gets corrupted again after 2 minutes. This problem only occurs in the Java class where I am writing the codes. Since my entire project is written in Java, I have no choice but to use Java. Your library is very nice and I want to use it. How can I solve this problem?

image

Custom Button Layout?

Can we use a custom button layout for this. I need 3 textViews of different sizes in the button.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.