Assign attributes such as app:strokeWidth in style - android

I want to create a style 100% equal to this button:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:backgroundTint="#color/red"
android:text="In XML"
android:textStyle="bold"
app:cornerRadius="25dp"
app:strokeColor="#color/black"
app:strokeWidth="2dp"/>
This is the style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="btn_xml" value="btn_xml" />
<style name="ProgrammaticallyStyle">
<item name="android:id">#id/btn_xml</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">5dp</item>
<item name="android:backgroundTint">#color/red</item>
<item name="android:paddingStart">30dp</item>
<item name="android:paddingEnd">30dp</item>
<item name="android:text">In XML</item>
<item name="android:textStyle">bold</item>
<item name="app:cornerRadius">25dp</item>
<item name="app:strokeColor">#color/black</item>
<item name="app:strokeWidth">2dp</item>
</style>
</resources>
But in style, the last 3 attributes start with app:xxx and cannot be assigned. I assumed that is because in xml I have the following sentence in button parent view:
xmlns:app="http://schemas.android.com/apk/res-auto"
Using sttributes without app: doesn't work, do I maybe need a specific parent for the style?
How can I assign these app:xxx attributes in style?

Related

Change Version Of Material 1.1.0 to 1.3.0

And my Second Question :
I use a TextInputLayout :
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#color/LightBlue"
android:theme="#style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
app:boxStrokeColor="#color/selector"
app:boxStrokeWidth="3dp"
app:startIconTint="#color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="numberDecimal"
android:textColor="#color/gold" />
</com.google.android.material.textfield.TextInputLayout>
The Styles file
<style name="AppTheme"
parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/Thistle</item>
<!-- use in get player information -->
<item name="CustomTextStyle">#style/Widget.App. TextInputLayout.
OutlinedBox</item>
</style>
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined"
parent="">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="boxCornerRadiusBottomEnd">20dp</item>
<item name="boxCornerRadiusBottomStart">20dp</item>
<item name="boxCornerRadiusTopEnd">20dp</item>
<item name="boxCornerRadiusTopStart">20dp</item>
<item name="android:hint">Number of player</item>
<item name="hintTextColor">#color/card1</item>
<item name="startIconDrawable">#drawable/ic_people</item>
</style>
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/player_information</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="android:textColorHint">#color/white</item>
<item name="startIconDrawable">#drawable/player</item>
<item name="startIconTint">#color/gold</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<itemname="materialThemeOverlay">#style/ThemeOverlay.App.
TextInputEditText.OutlinedBox</item>
<item name="hintTextColor">#color/AntiqueWhite</item>
<!-- .... -->
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox"
parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<!-- to change the cursor color -->
<item name="colorControlActivated">#color/white</item>
</style>
That is my selector file
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/DarkSeaGreen"
android:state_focused="true"/>
<item android:color="#color/white"/>
</selector>
and Attrs
<resources>
<attr name="customTextInputStyle" format="reference" />
<attr name="CustomTextStyle" formet ="reference"/>
</resources>
When I change the version of the material 1.1.0 to 1.3.0 ,The shape of The text input layout1 I created before is distorted. It became wider than it was before. I could not find the reason for this change.As you can see in the picture, the text inputlayout is very wide and the hinttext still looks black on the back.
The main issue is in the ThemeOverlay. You have to add the parent ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox.
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">#color/...</item>
</style>
It is needed because the default style Widget.MaterialComponents.TextInputLayout.OutlinedBox which you are extending has defined a own materialThemeOverlay and
without the parent dependency you are losing the default behaviour.
Also in your xml layout remove android:theme="#style/ThemeOverlay.AppTheme.TextInputEditText.Outlined". You don't need it because you are already using materialThemeOverlay in the style and the theme defined in the xml layout overrides it and this theme overlay is wrong.
Also:
use a min width because you are using a big corner radius 15dp
<com.google.android.material.textfield.TextInputLayout
android:minWidth="150dp"
android:layout_width="wrap_content"
Finally the color used by the hint:
<item name="android:textColorHint">#color/red600Dark</item>
<item name="hintTextColor">#color/teal_700</item>
Final layout:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.App.TextInputLayout.OutlinedBox"
android:minWidth="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:startIconTint="#color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:textColor="#color/gold" />
</com.google.android.material.textfield.TextInputLayout>
with:
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/text_input_stroke_selector</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="startIconDrawable">#drawable/ic_...</item>
<item name="startIconTint">#color/...</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<item name="materialThemeOverlay">#style/ThemeOverlay.App.TextInputEditText.OutlinedBox</item>
<item name="android:textColorHint">#color/....</item>
<item name="hintTextColor">#color/....</item>
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">#color/....</item>
</style>

Align all columns in list view

I was wondering how I can manage to align all columns in rows. I am using a ListView, where I display a list of drugs for my game. The columns are different sizes each row. I would like to see that each column has the same width all down to the end of the list, but not have same width overall.
As you can see from the picture, the columns are not aligned. I draw the lines to make it even more obvious what I would like. You can also see that the buttons are to close to the other column. With the arrow on the picture I wanted to make it clear that those buttons should be placed more to the end of the row.
My implementation uses the following styles:
<!-- List style for the drug sell list -->
<style name="traderY.List">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_alignParentTop">true</item>
</style>
<!-- Header style for quantity column -->
<style name="traderY.HeaderQuantityText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.15</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Header style for cost column -->
<style name="traderY.HeaderCostText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Header style for name column -->
<style name="traderY.HeaderNameText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.45</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#EDEFF0</item>
</style>
<!-- Row style for quantity column -->
<style name="traderY.QuantityListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.15</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for cost column -->
<style name="traderY.CostListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for name column -->
<style name="traderY.NameListText">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.45</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:padding">4dip</item>
<item name="android:layout_margin">4dip</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Row style for button column -->
<style name="traderY.ListButton" parent="#android:style/Widget.Button">
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:gravity">center</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.6</item>
<item name="android:background">#drawable/custom_btn_black_pearl</item>
<item name="android:padding">4dip</item>
</style>
As you can see I set or I try to set the column width by using those two items:
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">0.20</item>
I was reading that you can set the width by using weight. I basically used the same values I would use to set percentages. If I understand correctly, the weight value represents the ratio between other components. I found this as a solution on a Stack Overflow question and I found it in several tutorials. One of the tutorials I found is this one here.
To share more light, here are also the layouts of the of all the components, starting with the fragment which contains the list view.
Fragment layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/money"
style="#style/traderY.TextCenter" />
<TextView
android:id="#+id/location"
style="#style/traderY.TextCenter" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/junkie_icon"/>
<ListView
android:id="#+id/drug_list"
style="#style/traderY.List"
android:layout_weight="1"/>
<TableRow
style="#style/traderY.ButtonRow">
<Button
android:id="#+id/nothing"
style="#style/traderY.ButtonCenter"
android:text="#string/exit"/>
</TableRow>
</LinearLayout>
Here is the header layout. As you can see I omit the last column for buttons, because there is no need to display a header for it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000">
<TextView
android:text="#string/header_quantity"
style="#style/traderY.HeaderQuantityText" />
<TextView
android:text="#string/header_cost"
style="#style/traderY.HeaderCostText" />
<TextView
android:text="#string/header_name"
style="#style/traderY.HeaderNameText" />
</LinearLayout>
And here is the layout for each row I use:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/drug_quantity"
style="#style/traderY.QuantityListText" />
<TextView
android:id="#+id/drug_cost"
style="#style/traderY.CostListText" />
<TextView
android:id="#+id/drug_name"
style="#style/traderY.NameListText" />
<Button
android:id="#+id/drug_sell_btn"
android:text="#string/sell_drugs_action"
style="#style/traderY.ListButton"/>
</LinearLayout>
Those are the style/layouts I use and I do not change any of those properties in the code. So the problem can only be in my XML files.
Does anyone know what am I doing wrong here? Maybe my investigation is wrong and I can not do it. I would appreciate any help or comments to solve this problem. If this is not even possible, then please let me know.
I found out that my solution was correct. The weight property did the job. For some unknown reason gradle did not see the changes when it was building the app. Or maybe it is the emulator. This was not the first time something like this happened. I will have to investigate why this even occur.
Increase weight of style="#style/traderY.QuantityListText". Make 0.2 or 0.3
Wrap your text views in a LinearLayout and set it to fill the parentView. In this way all the buttons will be aligned to the right.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/drug_quantity"
style="#style/traderY.QuantityListText" />
<TextView
android:id="#+id/drug_cost"
style="#style/traderY.CostListText" />
<TextView
android:id="#+id/drug_name"
style="#style/traderY.NameListText" />
</LinearLayout>
<Button
android:id="#+id/drug_sell_btn"
android:text="#string/sell_drugs_action"
style="#style/traderY.ListButton"/>
</LinearLayout>

applying style to textview drawable

I have a layout for a TextView and drawable as such...
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#drawable/menu6" />
<TextView
style="#style/dashboard_textview"
android:text="#string/menu6_text />
</LinearLayout>
as you can see the image uses a style attribute which looks like this
<style name="dashboard_imageview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:scaleType">fitCenter</item>
</style>
the linear layout's style surrounding it looks like this
<style name="dashboard_content_horizontal">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">3</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>
and TextView's style
<style name="dashboard_textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
</style>
this all works and looks exactly how I want it to look. however, because of this eclipse warning
"This tag and its children can be replaced by one
and a compound drawable" I decide to try to do this with just a TextView and drawable
like such..
<TextView
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu6"
android:drawableBottom="#drawable/my_drawable"
android:padding="5dp" />
this renders the image too small.. I don't see a way to apply a style to the image to get it like I want it.. anyone know the answer? is even possible?

Android layout error: "Resource id <res_id> is not of type STYLE (instead attr)"

I'm seeing an error I've never seen before w/ Android that's preventing some of my layout files from rendering in Eclipse. They render fine at runtime.
The error that shows up in the graphical layout editor (and my Error log) is:
"Resouce id 0x1010081 is not of type STYLE (instead attr)"
I've searched for resource id 0x1010081 in my R files, and I can't find it so I'm guessing maybe somehow I have a conflict with a built in Android attr. I've also verified that all of my style attributes below point to actual styles and not attr. Any help appreciated.
Here's my full layout code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bkg_light"
android:padding="#dimen/padding_med" >
<RelativeLayout
android:id="#+id/relativeLayout_activity"
android:layout_width="fill_parent"
android:layout_height="#dimen/button_height"
android:background="#drawable/xml_button"
android:padding="#dimen/padding_med" >
<TextView
style="#style/text_large_bold_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/activity" />
<TextView
android:id="#+id/textView_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/margin_med"
android:layout_toLeftOf="#+id/textView_arrow_right_start_date"
android:text="#string/none_selected"/>
<TextView
android:id="#+id/textView_arrow_right_start_date"
style="#style/arrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<!-- kv Duration -->
<RelativeLayout
android:id="#+id/relativeLayout_duration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout_activity"
android:layout_marginTop="#dimen/margin_large"
android:background="#drawable/xml_button">
<TextView
android:id="#+id/textView_duration"
style="#style/text_large_bold_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/duration_lc"
android:paddingLeft="#dimen/padding_med"/>
<Spinner
android:id="#+id/spinner_duration"
android:layout_width="wrap_content"
android:layout_height="#dimen/button_height"
android:layout_alignParentRight="true"
android:entries="#array/array_durations"
android:prompt="#string/duration_lc"
android:spinnerMode="dropdown"
android:clickable="false"/>
</RelativeLayout>
</RelativeLayout>
And here's my styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="arrow_right">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_xxlarge</item>
<item name="android:text">#string/arrow_right</item>
</style>
<style name="button_blue">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/white</item>
<item name="android:background">#drawable/selector_button_blue</item>
<item name="android:padding">#dimen/padding_med</item>
</style>
<style name="button_blue_small">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/white</item>
<item name="android:background">#drawable/selector_button_blue_small</item>
<item name="android:padding">#dimen/padding_med</item>
</style>
<style name="button_dark">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/white</item>
<item name="android:background">#drawable/selector_button_dark</item>
<item name="android:padding">#dimen/padding_med</item>
</style>
<style name="button_light">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
<item name="android:background">#drawable/selector_button_light</item>
<item name="android:padding">#dimen/padding_med</item>
</style>
<style name="button_light_small">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
<item name="android:textSize">#dimen/text_small</item>
<item name="android:background">#drawable/selector_button_light</item>
<item name="android:padding">#dimen/padding_small</item>
</style>
<style name="text_small_gray_light">
<item name="android:textSize">#dimen/text_small</item>
<item name="android:textColor">#color/gray_light</item>
</style>
<style name="text_med_bold_gray_light">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_med</item>
<item name="android:textColor">#color/gray_light</item>
</style>
<style name="text_large_bold_white">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_large</item>
</style>
<style name="text_large_bold_black">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_large</item>
<item name="android:textColor">#color/black</item>
</style>
<style name="text_large_bold_gray_dark">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_large</item>
<item name="android:textColor">#color/gray_dark</item>
</style>
<style name="text_large_bold_gray_light">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_large</item>
<item name="android:textColor">#color/gray_light</item>
</style>
<style name="text_large_bold_white">
<item name="android:textStyle">bold</item>
<item name="android:textSize">#dimen/text_large</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="text_large_white">
<item name="android:textSize">#dimen/text_large</item>
<item name="android:textColor">#color/white</item>
</style>
</resources>
And here's my custom theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.P90X" parent="#style/Theme.Sherlock">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
I also have this problem, with the same resource ID showing up. It disappears when I change android:spinnerMode to "dialog" so I suspect it's not a problem with your code.
The id in question refers to the android attribute spinnerStyle. See the doc for R.attr
I found a workaround, namely replace
android:spinnerMode="dropdown"
with
android:spinnerStyle="#android:style/Widget.Spinner.DropDown".
Have you tried changing the each style property to something like this:
style="?attr/text_large_bold_white"
As JulianSymes says the problem is
android:spinnerMode="dropdown"
His solution (replace for android:spinnerStyle="#android:style/Widget.Spinner.DropDown") runs on my phone but not on my tablet
My solution is more simple: DELETE THE LINE.
spinnerMode="dropdown" is by default, therefore it's unnecesary
Delete all style elements and then add them one after another and always check if it still renders. So you can at least find out which one's to blame.
As Google points to this page for this error, and for the sake of posterity...
In my case, in a whim, I closed and reopened eclipse and boom the error was gone and eclipse had no problem rendering the preview.
Though I strongly believe this may not be the case for all.
If you feel you have done everything right, I guess, it won't hurt restarting eclipse.

problem changing style in a Spinner

i need to implement an application in android using styles. I know that, difining an style for each object in styles.xml, it's possible to stablish diferent styles for: Textview, Buttons, editviews..but in the special case of spinner it doesn't work. this is my example:
this is the layout main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
style="#style/TextviewVerde"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/escribenombre"
/>
<EditText
style="#style/EditviewAzul"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/TxtNombre"
/>
<Spinner
style="#style/SpinnerRojo"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/TxtSpinner"
android:prompt="#string/seleccionetexto"
/>
<Button
style="#style/BotonBlanco"
android:id="#+id/BtnHola"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pulse aqui"
/>
</LinearLayout>
and this is the styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextviewVerde" >
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">5pt</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="TextviewRosa" >
<item name="android:textColor">#5F04B4</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">15pt</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="EditviewAzul" >
<item name="android:textColor">#0000FF</item>
<item name="android:textSize">8pt</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:shadowColor">#0000FF</item>
</style>
<style name="SpinnerRojo" >
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#DF0101</item>
<item name="android:gravity">center</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">11pt</item>
<item name="android:drawSelectorOnTop">true</item>
</style>
<style name="BotonBlanco">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">12pt</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:clickable">true</item>
</style>
</resources>
every object works well, but the spinner doesn't change its appearance. My boss told me that i have to implement styles without changing the *.java file, what can i do?? i need to change the colour of the spinner options, the backgound, add some pics.. etc. thanks a lot for the help
http://www.mokasocial.com/2011/03/easily-create-a-default-custom-styled-spinner-android/
To make custom styled dropdown when the spinner is clicked, you should create a custom Adapter with a reference to your layout xml defining the rows of the list.
For example:
String[] elements = {"optionA", "optionB"};
Spinner s = (Spinner) findViewById(R.id.your_spinner_id);
ArrayAdapter adapter = new ArrayAdapter<String>(this,
R.id.textViewId, elements);
adapter.setDropDownViewResource(R.layout.your_dropdown_layout);
Where textViewId should be a child view in your_dropdown_layout.
Hope that helped.
Ripityom

Categories

Resources