Since my popup background is white in color I need to change the color of the spinner divider. I have tried styling the spinner in the following way but it does not work:
styles.xml
<style name="applicationTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:dropDownListViewStyle">#style/SpinnerStyle</item>
</style>
<style name="SpinnerStyle" parent="android:Widget.ListView.DropDown">
<item name="android:divider">#0193DE</item>
<item name="android:dividerHeight">1dp</item>
</style>
main xml
<Spinner
android:id="#+id/year"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="#drawable/apptheme_spinner_default_holo_dark"
android:layout_marginLeft="75dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:spinnerMode="dropdown"
style="#style/SpinnerStyle"
android:popupBackground="#FFFFFF" />
java
ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year);
adapter_year.setDropDownViewResource(R.layout.custom_spinner_popup);
custom_spinner_holidays.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#android:color/white" />
custom_spinner_popup
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="#0193DE" />
Can I just combine all these into one?
You need to put this theme in your manifest file like this:
<activity android:name="com.example.activity.Solution"
android:theme="#style/applicationTheme">
</activity>
Maybe the best idea it's doing your own spinner and you can style it in the way that you want. Take a look in the next thread it was so useful for me.
How to customize a Spinner in Android
Related
I have simple requirement to display some text in the actionBar near the menu. How can I acheive it?
What it looks like now?
What I need?
Try this ActionBar menu sample:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourApp="http://schemas.android.com/apk/res-auto"
>
... ...
<item
android:id="#+id/item_text"
yourApp:showAsAction="always"
yourApp:actionLayout="#layout/action_text"
/>
</menu>
Then you need a layout action_text for your TextView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
>
... ...
<TextView android:id="#+id/lb_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/your_text"
android:textSize="10sp"
android:textColor="#color/white"
/>
</RelativeLayout>
Hope this help!
<item
android:id="#+id/action_refresh"
android:icon="#android:drawable/ic_input_add"
android:title="Options"
app:showAsAction="withText|always" />
<item
android:id="#+id/action_options_unused"
app:showAsAction="withText|always"
android:title="Options"
/>
Don't set a android:icon if you don't want an icon appearing at the left side of your textual item. Also make sure this <item> is the last one in your menu's XML file.
I'm putting some settings to the checkbox, and it works. But when I take them into a style and apply them, it doesn't. Per below, first button uses the style (NOT working), second one direct settings (works). What's wrong with my style file, per below? Tks
<CheckBox android:id="#+id/mon"
android:text ="Mon"
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="Monday"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
style="#style/FilledCheckButton"
/>
<CheckBox android:id="#+id/tue"
android:text="Tue"
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="Tuesday"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/mon"
android:gravity="center"
android:background="#drawable/v4_btn_weekday"
android:button="#drawable/v4_btn_weekday"
/>
My style file:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="FilledCheckButton" parent="android:style/Widget.CompoundButton.CheckBox"
android:background="#drawable/v4_btn_weekday"
android:button="#drawable/v4_btn_weekday"
android:gravity="center">
</style>
</resources>
Try this way
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="FilledCheckButton" parent="#android:style/Widget.CompoundButton.CheckBox">
<item name="android:background">#drawable/v4_btn_weekday</item>
<item name="android:button">#drawable/v4_btn_weekday</item>
<item name="android:gravity">center</item>
</style>
For more information go to http://aproblemlikemaria.wordpress.com/2011/09/26/theming-and-styling-in-android/
I have created a custom title bar with the following.
myapptitle.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTitle"
android:text="#string/app_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/titletextcolor"
android:textSize="14sp"
android:layout_gravity="top"
/>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
<item name="android:windowTitleSize">40dip</item>
</style>
</resources>
manifext.xml
<application
android:label="#string/app_name"
android:theme="#style/customTheme" >
.....
I have created a customList adapater and a layout for that like the one below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/icon"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="10dip"
android:layout_marginTop="4dip"
android:contentDescription="#string/app_msg_title"
android:src="#drawable/logo_small" >
</ImageView>
<TextView
android:id="#+id/msgDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
/>
<TextView
android:id="#+id/msgTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14sp" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="12sp" >
</TextView>
</LinearLayout>
In my list activity I have given the below code on onCreate method.
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.myapptitle);
But somehow while running the application I'm getting the title bar without any text in it at all. In my strings.xml for app_name i have My Notifications as text.
Appreciate all your time and help.
Edited
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">#color/titlebackgroundcolor</item>
</style>
</resources>
Change your style.xml like below:
<resources>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle"> #style/CustomWindowTitleBarBG</item>
</style>
</resources>
Then
In manifest file, use TitleBarTheme in application tag and for activity use like below:
android:theme="#android:style/Theme.NoTitleBar"
and in activity class use your code which is:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.myapptitle);
I'm confused with the answers to this question.
I have the following in values-14/styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
<style name="ListTheme" parent="AppTheme">
<item name="android:activatedBackgroundIndicator">#drawable/br_listitem</item>
</style>
</resources>
then I have defined in my drawable dir br_listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/SlateBlue" android:state_activated="true"/>
</selector>
and finally in my listitem.xml file I have
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="600dp"
android:gravity="left|center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="5dp"
style="#style/ListTheme"
android:background="?android:attr/activatedBackgroundIndicator">
I get a light orange color when pressed and light green after. The activated background works, but it's not using my colors...
Thanks !
~ Jay
Based on comments I made the following changes. I pulled the style out of the LinearLayout and put it in my listview as follows:
<ListView
style="#style/ListTheme"
android:id="#+id/XYZList"
android:layout_height="600dp"
android:layout_width="600dp"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="center|top"
android:layout_row="2"
android:layout_rowSpan="10"
android:focusable="true"
android:choiceMode="multipleChoice"
android:background="#80D0D0D0"
>
</ListView>
How to set the text size, text color and other parameters in one xml and than assign them to the imagebutton in android?
I can set the parameters manually for each button, but if there are more than 3 buttons it becomes a nightmare. What is the best practices for doing this?
You can use styles for that
http://developer.android.com/guide/topics/ui/themes.html
Create a style depending on your requirement's add that to your button like this style="#style/your_style". look at this tutorial Styles and Themes
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomText" parent="#style/Text">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#008</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<EditText
style="#style/CustomText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="#string/hello" />