I am having a simple dashboard layout with several Button's that show image and text.
<Button
android:id="#+id/some_id"
style="#style/DashboardButton"
android:drawableTop="#drawable/image"
android:text="#string/text" />
<style name="DashboardButton">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:drawablePadding">2dp</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#000000</item>
<item name="android:background">#null</item>
</style>
However, I can't seem to influence the size of the image by modifying layout_width or layout_height. I need the images to be bigger on tablets, now they are too small there.
Is there a way to do this easily?
Related
I am trying to define button properties on style.
My code is
<style name="button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
And using as
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/button"/>
But the color of the button's normal state is not changing.
This button style is only for some buttons. Not for all butons.
What to do now?
edit after question clarification
Save you style.xml in res/values/
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
Apply it like so:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/custom_button"/>
first answer
You need to inherit the parent style.
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
That way all your Button's that are not styled will have your custom style. i.e. no need to put in the style value.
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"/>
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?
I created a theme and set its:
SpinnerStyle
SpinnerItemStyle
SpinnerDropDownItemStyle
Here is the code:
<style name="MySpinnerTheme" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
<item name="android:spinnerStyle">#style/MySpinner</item>
<item name="android:spinnerDropDownItemStyle">#style/MySpinnerDropDown</item>
</style>
<style name="MySpinner" parent="#android:style/Widget.Spinner">
<item name="android:background">#drawable/base1</item>
<item name="android:clickable">true</item>
<item name="android:enabled">true</item>
</style>
<style name="MySpinnerItem" parent="android:Widget.TextView.SpinnerItem">
<item name="android:background">#drawable/base1</item>
<item name="android:textAppearance">#style/MyTextAppearanceSpinnerItem</item>
<item name="android:padding">2dp</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingRight">6dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:gravity">center</item>
</style>
<style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
<item name="android:textSize">20sp</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingRight">6dp</item>
</style>
<style name="MySpinnerDropDown" parent="android:Widget.Spinner.DropDown">
<item name="android:textColor">#FFF</item>
<item name="android:background">#drawable/base1</item>
<item name="android:gravity">center</item>
</style>
I set the theme for one Activity. When I added a CheckBox to it, it gets disabled and I can't click it.
If I set text to it, it gets written inside the clickable area.
Here is its code:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cboxData"
android:padding="4dp"
android:clickable="true"
android:enabled="true"
android:focusable="true"
android:text="sdsd"
/>
The phone is Android 2.3.
What's wrong with my CheckBox?
It was my mistake: I used setEnabled() instead of setChecked(). No wonder I began to use C#-like properties instead of setXY :)
I have made a very simple compound view:
<LinearLayout>
<ImageView />
<EditText />
</LinearLayout>
Everything worked fine until I have decided to style the Edit text throught my project:theme:
<style name="Theme.MyProject" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Theme.MyProject.ActionBar</item>
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/Widget.Playout.ActionBar</item>
<item name="android:buttonStyle">#style/Theme.Theme.MyProject.Button</item>
<item name="android:editTextStyle">#style/Theme.Theme.MyProject.EditText</item>
</style>
and
<style name="Theme.Playout.EditText">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/field_text</item>
<item name="android:background">#color/field</item>
<item name="android:minHeight">50dp</item>
<item name="android:padding">5dp</item>
<item name="android:gravity">center</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
Now my EditText is beautiful but is not gaining focus so text cannot being entered (so useful). It works fine adding values directly to the Compound view from layout but I whould like to do it from a confortable theme.
Thanks in advance!
Try this:
<style name="Theme.Playout.EditText">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/field_text</item>
<item name="android:background">#color/field</item>
<item name="android:minHeight">50dp</item>
<item name="android:padding">5dp</item>
<item name="android:gravity">center</item>
<item name="android:fontFamily">sans-serif-light</item>
<!-- I added these attributes: -->
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
</style>
I need to set the ImageView's src within my style, but I cant find a good example of anyone doing this and when I try the below code, it crashes the app.
<ImageView android:src="#style/TitleBarImage"></ImageView>
<style name="TitleBarImage">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:src">#drawable/whiteButton</item>
</style>
This should be simple. What gives?
Your xml is incorrect:
<ImageView style="#style/TitleBarImage" />
And styles.xml :
<style name="TitleBarImage">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:src">#drawable/whiteButton</item>
</style>