-
-
Save LOG-TAG/4a9c09b6c2d6a137871c to your computer and use it in GitHub Desktop.
Theme Aware Material Design Spinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.v7.widget.Toolbar | |
android:id="@+id/toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="?attr/actionBarSize" | |
android:background="?attr/colorPrimary" | |
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" | |
app:popupTheme="@style/AppTheme.PopupOverlay"> | |
<Spinner | |
android:id="@+id/main_spinner" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
</android.support.v7.widget.Toolbar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spinner spinner = (Spinner) findViewById(R.id.main_spinner); | |
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getSupportActionBar().getThemedContext(), | |
R.layout.spinner_list_style, | |
getResources().getStringArray(R.array.countries)); | |
spinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); | |
spinner.setAdapter(spinnerAdapter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Used for Spinner's list item--> | |
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/spinner_dropdown" | |
style="?android:attr/spinnerDropDownItemStyle" | |
android:layout_width="match_parent" | |
android:layout_height="?android:attr/listPreferredItemHeight" | |
android:ellipsize="marquee" | |
android:singleLine="true" | |
android:textColor="?attr/textColorAlertDialogListItem" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Used for the Spinner title indicator--> | |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/spinner_list_item" | |
style="@style/TextAppearance.AppCompat.Title" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:ellipsize="marquee" | |
android:paddingEnd="@dimen/activity_margin" | |
android:paddingRight="@dimen/activity_margin" | |
android:singleLine="true" | |
android:textColor="@android:color/white" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Base application theme (LIGHT). --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | |
... | |
<item name="spinnerStyle">@style/MySpinner</item> | |
</style> | |
<!-- Base application theme (DARK). --> | |
<style name="AppTheme.Dark" parent="Theme.AppCompat"> | |
... | |
<item name="spinnerStyle">@style/MySpinner.Dark</item> | |
</style> | |
<style name="MySpinner" parent="Base.Widget.AppCompat.Spinner"> | |
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item> | |
</style> | |
<style name="MySpinner.Dark" parent="MySpinner"> | |
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment