tweaking Android built-in UI
at first i thought it was a great big deal, involving styles and all sorts of stuff. in the end i reckon that i should really have just KISS.
the aim
the built-in Android UI elements (e.g. simple_spinner_dropdown_item
) aren't always satisfying. but creating *completely* custom UI elements is not what's wanted. the comprimise is to make changes to the built-in elements only where needed. e.g. i might want to just change the text color.
how
first, use the built-in UI elements as if that's what's wanted:
SimpleCursorAdapter scaRows = new SimpleCursorAdapter(
getApplicationContext(), android.R.layout.simple_spinner_item, rows, rowsFrom, rowsTo);
scaRows.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
now if you are using eclipse just like me, just hold CTRL
and click android.R.layout.simple_spinner_item
. to that, a new file would be opened, which is simple_spinner_item.xml
. copy all its contents to a layout file in the layout folder in your project folder in your workspace, e.g. /res/layout/simple_spinner_item.xml
, so that you can reference it in Java code like R.layout.simple_spinner_item
, instead of using the android
stuff anymore.
and then, simply add new attributes to the elements. e.g., add a android:textColor
attribute:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true" />
and that does it!
references,
when i hadn't yet realized how simple the job was, i was looking over a whole bunch of stuff. here's some of them:
- Styles and Themes | Android Developers
- android - How do I change the font color of the selection list in a spinner? - Stack Overflow
- android spinner item text color override - Google Search
- Styling Android With Defaults - Android Developer
- 善用Android预定义样式 - RayLee - 博客园
- Android selector & text color - Stack Overflow
- Styles and Themes | Android Developers