You can implement PowerSpinnerView in your XML layout as the below example. You can use PowerSpinnerView same as TextView. For instance, you can set the default text with the hint and textColorHint attributes..
Note: It's highly recommended to set the height size of the item with the spinner_item_height attribute or the entire height size of the popup with the spinner_popup_height to implement the correct behaviors of your spinner.
Show and Dismiss
By default, the spinner popup will be displayed when you click the PowerSpinnerView, and it will be dismissed when you select an item. You can also show and dismiss manually with the methods below:
powerSpinnerView.show() // show the spinner popup.
powerSpinnerView.dismiss() // dismiss the spinner popup.// If the popup is not showing, shows the spinner popup menu.// If the popup is already showing, dismiss the spinner popup menu.
powerSpinnerView.showOrDismiss()
You can customize the default behaviours of the spinner with the method and property below:
// the spinner popup will not be shown when clicked.
powerSpinnerView.setOnClickListener { }
// the spinner popup will not be dismissed when item selected.
powerSpinnerView.dismissWhenNotifiedItemSelected =false
OnSpinnerItemSelectedListener
You can listen the selection of the spinner items with the setOnSpinnerItemSelectedListener method below:
You can select an item manually/initially with the method below:
powerSpinnerView.selectItemByIndex(4)
Note: selectItemByIndex must be invoked after setting items with the setItems method.
Store and Restore a selected Position
You can store and restore the selected position automatically and it will be re-selected automatically when the PowerSpinnerView is inflated with the property below:
powerSpinnerView.preferenceName ="country"
You can also set the property above with the attribute below in your XML layout:
app:spinner_preference_name="country"
You can remove or clear the stored position data with the methods below:
You can also implement your own custom adapter and bind to the PowerSpinnerView. Firstly, create a new adapter and viewHolder, which extend each RecyclerView.Adapter and PowerSpinnerInterface below:
You can use PowerSpinnerView in your PreferenceScreen XML for building preferences screens. Add the dependency below to your module's build.gradle file:
You don't need to set preferenceName attribute, and OnSpinnerItemSelectedListener should be set on PowerSpinnerPreference. You can reference this sample codes.
Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed. But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released. So you can solve the memory leak issue simply by setting the lifecycle owner with the method below:
.setLifecycleOwner(lifecycleOwner)
By setting the lifecycle owner, the dismiss() method will be invoked automatically before destroying your activity or fragment.
PowerSpinnerView Attributes
Attributes
Type
Default
Description
spinner_arrow_drawable
Drawable
arrow
arrow drawable.
spinner_arrow_show
Boolean
true
sets the visibility of the arrow.
spinner_arrow_gravity
SpinnerGravity
end
the gravity of the arrow.
spinner_arrow_padding
Dimension
2dp
padding of the arrow.
spinner_arrow_tint
Color
None
tint color of the arrow.
spinner_arrow_animate
Boolean
true
show arrow rotation animation when showing.
spinner_arrow_animate_duration
Integer
250
the duration of the arrow animation.
spinner_divider_show
Boolean
true
show the divider of the popup items.
spinner_divider_size
Dimension
0.5dp
sets the height of the divider.
spinner_divider_color
Color
White
sets the color of the divider.
spinner_popup_width
Dimension
spinnerView's width
the width of the popup.
spinner_popup_height
Dimension
WRAP_CONTENT
the height of the popup.
spinner_item_height
Dimension
WRAP_CONTENT
a fixed item height of the popup.
spinner_popup_background
Color
spinnerView's background
the background color of the popup.
spinner_popup_animation
SpinnerAnimation
NORMAL
the spinner animation when showing.
spinner_popup_animation_style
Style Resource
-1
sets the customized animation style.
spinner_popup_elevation
Dimension
4dp
the elevation size of the popup.
spinner_item_array
String Array Resource
null
sets the items of the popup.
spinner_dismiss_notified_select
Boolean
true
sets dismiss when the popup item is selected.
spinner_debounce_duration
Integer
150
A duration of the debounce for showOrDismiss.
spinner_preference_name
String
null
saves and restores automatically the selected position.
Copyright 2019 skydoves (Jaewoong Eum)
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 L
Hello,
There's a bug that is being reported by crashlytics on Android 5 and 6 and I faced when testing on Android 4.4 that causes the app to crash when using the spinner.
it's working fine on Android 10 and Android 8
this the logcat
Describe the Bug:
Fatal Exception: java.lang.IllegalArgumentException
The observer class has some methods that use newer APIs which are not available in the current OS version. Lifecycles cannot access even other methods so you should make sure that your observer classes only access framework classes that are available in your min API level OR use lifecycle:compiler annotation processor.
Im using Kotlin with PowerSpinner, setting the onSpinnerOutsideTouchListener using setOnSpinnerOutsideTouchListener { view, motionEvent -> } does not get fired while touching outside spinner when the spinner is open
Expected Behavior:
Expect to get event fired when touching outside spinner when the spinner is open, so that I could close the spinner. It would be good if the spinner could be closed when user click the physical back button.
Describe the Bug:
Whenever I add a com.skydoves.powerspinner.PowerSpinnerView to my fragment I get a notification from LeakCanary about a memory leak caused by the PowerSpinnerView. I don't do anything else with it with code, it's just this.
Description:
Java code i wrote to dismiss the spinner when touched outside:
spinnerView.setOnSpinnerOutsideTouchListener((view, motionEvent) -> {
spinnerView.dismiss();
return null;
});
this does not work
Expected Behaviour:
Spinner should dismiss when touched/swiped outside spinner view
Arrow always shows white on older Android version. Even if I change spinner_arrow_tint to #000000
Expected Behavior:
Arrow color should be the same color as the text color, since both are set to the same value.
Arrow color is changeable on simulator and on Samsung A10.
How to code for setOnSpinnerItemSelectedListener , while searching i found only kotlin code.
can anyone help to code it to get the position of selected item.
Thanks
In cases where we have a fragment that uses a custom view e.g search bar, and that custom view has a recycler view
and in the adapter we use power spinner. If we have opened the spinner and then dismiss the custom view, as result the adapter will be destroyed but the power spinner cannot be dismissed and it's still visible.
Expected Behavior:
The power spinner should be dismissed when we destroy a view that contains the spinner.
Describe the Bug:
if set arrowTint color programmtically, Selected IconSpinnerItem's icon not showing.
Please see attached screenshot.
https://monosnap.com/file/2L7mCqwPNE76JJklQ6wePr3IYOG9B0
I am loading some images from a remote server (using Glide), and I want to use them as icons in the spinner. The problem is that it takes time to load the images from the server, so right now I need to load all of the images, and only then add the items to the spinner. It would be much better if I could populate the spinner with text only, and then dynamically add the icons.
Describe the solution you'd like:
I'd like to have an option to dynamically set the icons, and as Glide works with ImagesView, a solution I am using for something else which I found quite friendly is to set the icons as ImageViews, and the have the library call ImageView.getDrawable on demand whenever an icon is done loading.
Describe alternatives you've considered:
I've considered just building my own spinner with images, as I don't really need a complex spinner, just some basic text and icons.
Items cannot be set dynamically.
If you first set items 1, size=5, select item 5,
and then set items 2, size=2,
the spinner will crash. Because olditem are obtained from new data sets.
Hi, overall PowerSpinner works very perfect but here is an issue that the spinner padding is not working, i want to give it custom padding from the end but it's not working, looks like a bug.
Expected Behavior:
The Spinner arrow should take custom padding from end to make it little more space from end(move from end).
Thanks
opened by ar5-rehman 0
Releases(1.2.4)
1.2.4(Aug 27, 2022)
What's Changed
Fix the spinner arrow doesn't show when the adapter is IconSpinnerAdapter by @skydoves in https://github.com/skydoves/PowerSpinner/pull/129
Full Changelog: https://github.com/skydoves/PowerSpinner/compare/1.2.3...1.2.4
Add a style to allow clients to customize the scrollbar by @skydoves in https://github.com/skydoves/PowerSpinner/pull/103
Added new spinner_popup_max_height attribute and property by @wxw-9527 in https://github.com/skydoves/PowerSpinner/pull/102
Implement the setSpinnerPopupMaxHeight method in builder and mark as public the property by @skydoves in https://github.com/skydoves/PowerSpinner/pull/104
Full Changelog: https://github.com/skydoves/PowerSpinner/compare/1.2.0...1.2.1
Removed overScrollMode in the body layout. (0e147d1)
Added more options on IconSpinnerItem for customizing related to text color, typeface, icon.
val text: CharSequence,
val icon: Drawable? = null,
@DrawableRes val iconRes: Int? = null,
@Px val iconPadding: Int? = null,
val iconGravity: Int = Gravity.START,
val typeface: Int? = null,
val gravity: Int? = null,
val textSize: Float? = null,
@ColorInt val textColor: Int? = null,
Changed OnSpinnerItemSelectedListener for notifying the previous selected item and its index.
Added OnSpinnerDismissListener interface and setOnSpinnerDismissListener function for listening dismissed spinner popup.
Added setIsFocusable function. Sets isFocusable of the spinner popup. The spinner popup will got a focus and [onSpinnerDismissListener] will be replaced.
Added a Boolean type disableChangeTextWhenNotified field and setDisableChangeTextWhenNotified(Boolean) function. If the value is true, disables changing text automatically when an item selection notified.
We can save and restore automatically using preferenceName attribute. References
We can save and restore the selected postion automatically.
If you select an item, the same position will be selected automatically on the next inflation.
Just use the below method or attribute.
spinnerView.preferenceName = "country"
We can implement PowerSpinner on PreferenceScreen xml. References
Android Developer Advocate @GetStream π₯ β’ GDE for Android β’ Open Source Software Engineer β€οΈ β’ Love coffee, music, magic tricks, and writing poems.
CircleProgressBar δΈζηζζ‘£ The CircleProgressBar extends View, It has both solid and line two styles. Besides, progress value can be freely customized. I
ACProgressLite English Version / δΈζηζ¬ An Android loading widget library. Lite and easy to use, strong customizability. Can be used to implement 'iOS'