要在应用为主题的按钮样式中使用layout_marginLeft? [英] To use layout_marginLeft in a button style applied as a theme?

查看:131
本文介绍了要在应用为主题的按钮样式中使用layout_marginLeft?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为按钮定义的样式使用了属性 layout_marginLeft = 30dip 。当我为每个按钮分别应用此样式时,将按需要放置左边界。

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.

但是随后我定义了一个主题,在其中将按钮样式分配给该属性 android:buttonStyle 并将其应用于我的项目。

但是,左边距属性将被忽略。知道我在这里必须做什么吗?

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如下:

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>


推荐答案

看起来这可以通过包装插图来实现

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

就像这样:

<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>

这篇关于要在应用为主题的按钮样式中使用layout_marginLeft?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆