bryanx / themed-toggle-button-group Goto Github PK
View Code? Open in Web Editor NEWCustomisable toggle buttons inside a FlexboxLayout.
License: MIT License
Customisable toggle buttons inside a FlexboxLayout.
License: MIT License
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>
Is there a way I can add buttons programmaticaly?
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
Hello,
How select ThemedToggleButton programmatically? I try use the method setSelected, but it doesn't work.
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.
At some point I would like to port this library to Jetpack Compose.
Some points to consider:
PR's are welcome.
Hello!
Can u add function like clearCheck() in the radiogroup to your library. It's will be very usefull i think
Because Bintray is shutting down hosting has to be moved to Bintray.
Issue in flexbox library: google/flexbox-layout#566
I tried creating an adapter and using FlexboxLayoutManager but it's not working, is there anyway to achieve multi selection with recyclerview?
Thanks.
An XML attribute to set the font resource would be great. Programmatic way to do it as well would be a bonus.
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.
java.lang.IllegalStateException: Cannot start this animator on a detached view!
There is no Unit type in Java hence i am currently unable to use applyToText since Textview -> Textview.setTextSize(x) gives an error.
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>
How can I fix this issue?
Hope to hearing from you soon.
Thanks.
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?
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") }
}
}
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
}
}
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.
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 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?
Does it support programmatically inserting items into an array for example?
Beside Themed Button's app:toggle_text="social"
xml attribute, another similar one is also available, i.e. android:text="some text"
xml attribute. What is this?
There is no method to select or deselect these Themed buttons, if I use setSelected(true/false), they stop working....
Is it possibile to add programmatically toggle's attributes like toggle_textSize
and margin
? I can’t find a solution
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
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>
Is there a way to select/toggle the buttons programmatically?
How can I make all my ThemedButton have the same width with different textSize ?
Note: My ThemedToggleButtonGroup is set to app:flexDirection="column"
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?
That's more flexible
Can we use a custom button layout for this. I need 3 textViews of different sizes in the button.
I have a hobbies list on Edit Profile Activity, so I want to select some buttons programmatically? How can I do this. Please help me...
thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.