Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To use layout_marginLeft in a button style applied as a theme?

I used an attribute layout_marginLeft="30dip" in a style defined for buttons. When I apply this style individually for each button, the left margin is placed as I wanted.

But then I defined a theme, where I assigned my button style to the attribute android:buttonStyle and applied it to my project.
However, the left margin property is ignored. Any idea what I must do here?

style.xml as follows:

<style name="btnstyle" parent="@android:style/Widget.Button">     <item name="android:layout_height">wrap_content</item>     <item name="android:layout_width">wrap_content</item>     <item name="android:layout_marginLeft">30dip</item>     <item name="android:textColor">#FFFFFF</item>        </style>   <style name="appstyle" parent="android:Theme">      <item name="android:buttonStyle">@style/btnstyle</item>  </style> 
like image 506
kiki Avatar asked Sep 23 '10 05:09

kiki


People also ask

How to set style for Button in android?

To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml.

How to style Button in Android studio?

To add a button, that has an Android style all you need to do is to drag and drop a button from the Palette to your layout. For most versions that would mean a grey button with all corners at 2dp roundness. Check our blog, if you need to learn more about using Android Studio Layout Editor.


1 Answers

It looks like this can be achieved by wrapping an insets tag around the shape.

Like this:

<inset xmlns:android="http://schemas.android.com/apk/res/android"     android:insetLeft="5dp"     android:insetRight="5dp"     android:insetTop="5dp"     android:insetBottom="5dp">  <shape       android:shape="rectangle">     <solid          android:color="#fff"/>     <stroke         android:width="1dp"         android:color="#333"/>     <corners          android:radius="10dp"/> </shape> </inset> 
like image 64
Fracdroid Avatar answered Oct 04 '22 18:10

Fracdroid