Android spinner set selected text color
It becomes an item ( android:textSize) in the new style file. The style is assigned to the parent attribute of the new MySpinnerLook style (prefixed with The TextSize attribute is removed from the my_spinner.xml TextView layout file. In the platform styles.xml is found the style.)
ANDROID SPINNER SET SELECTED TEXT COLOR ANDROID
With X being the API level of the current Android platform. (The Android styles.xml can be viewed in the platforms/android-X/data/res/values folder, under the android-sdk folder. These can be viewed in Android's styles.xml file, not the project's styles.xml. This new style will inherit from an existing Android style. The name attribute given here is MySpinnerLook. In the new file a style element is defined. Click OK, other values remain as default (Source set is main, Directory name is values, no Chosen qualifiers). Highlight the the res/values folder and use the context menu (normally right-click) or the File menu and choose New, then Values resource file, give it a name, here it is called my_styles.xml, the name is not important as long as a file of the same name does not exist. To achieve this create a new style XML file. Fortunately by using the Android feature that allows for the styling on Views to inherit from existing styles it is possible to get the Spinner back to the default theme but with the text size increase. This could be solved by assigning colors to the TextView, however, this would remove the Spinner styling from any theme that is being used on the device. The text in the Spinner is now larger, but the default styling has been lost. Pass the new layout to the ArrayAdapter creation (the id has to be text1 for the Adapter to use the View), replacing android.R.layout.simple_spinner_item with R.layout.my_spinner: ArrayAdapter adapter = ArrayAdapter.createFromResource( The my_spinner.xml will be similar to this: The layout_width is match_parent and layout_height is wrap_content. Set the id of the TextView in the new layout file to text1, and set a textSize of 24sp. Highlight the folder in the Project explorer and use the context menu (normally right-click) or the File menu and choose New, then Layout resource file. Here a new Android layout XML file is created in the res/layout folder. Instead of using an Android default layout like simple_spinner_item. The solution to changing the Android Spinner text size is to pass in a custom layout. This means trying to change the size of the text being displayed with android:textSize or android:textAppearance attributes on the Spinner definition is a no go. The Properties list in Studio for the Spinner does not have a text size attribute ( android:textSize), unlike, for example a TextView. Why Using android:textSize on Spinner Does Not Work Follow the article Load Values into an Android Spinner to get a working Spinner running.
An Empty Activity is used with other settings left at their default values.
ANDROID SPINNER SET SELECTED TEXT COLOR CODE
When entering code in Studio add import statements when prompted by pressing Alt-Enter.) Create a New Studio ProjectĬreate a new project in Android Studio, here called Spinner Style. The example code can be changed to meet your own requirements. (This Android Spinner styling tutorial assumes that Android Studio is installed, a basic App can be created and run, and the code in this article can be correctly copied into Android Studio. This tutorial covers changing the style of the text values in an Android Spinner. This has implications if the size of the Spinner text, or the color of the text needs to be changed. The previous article used the existing Android simple_spinner_item as the View for the data items. That is assigned when the Adapter that links the data to the Spinner is created.
It was stated in the article that the Spinner definition in the layout file does not define the View that the data being displayed uses. The article Load Values into an Android Spinner showed how a Spinner is set up.
Changing Android Spinner Text Size with Styles