怎样降低一个Android按钮对象中的文本两端内填充? [英] How do I reduce the inner padding around the text within an Android button object?

查看:143
本文介绍了怎样降低一个Android按钮对象中的文本两端内填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在现阶段,我有一个按钮,它看起来像上面的第一个图像。我如何减少填充周围的按钮本身内的文本(看起来更像第二图像)?

So, at the moment I have a button which looks like the first image above. How do I reduce the padding around the text inside the button itself (To look more like the second image)?

布局宽度和高度被设置为:

Layout width and height is set as:

android:layout_width="match_parent"
android:layout_height="wrap_content"

在自定义样式形状具有参数

The custom style shape has parameters"

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">

通过其余的只是被色彩属性和半径值。

With the rest just being color attributes and radii values.

只是为了说清楚,我希望按钮的框架拥抱登陆的文字更近。

Just to make it clear, I want the frame of the button to hug the "Login" text closer.

所有帮助和反馈大大AP preciated。谢谢你。

All help and feedback is greatly appreciated. Thanks.

推荐答案

我花了永远找到这一点,但在填充围绕一个按钮上的文本是不是真的填充的。默认Widget.Button样式包含minHeight属性。改变了minHeight按钮将允许您按预期的调整填充。

It took me forever to find this but the "padding" around the text in a button isn't really padding at all. The default Widget.Button style includes a minHeight property. Changing minHeight on the button will allow you to adjust padding as expected.

<Button
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/test"
        android:textColor="@color/black"
        android:minHeight="40dip"/>


<style name="Widget.Holo.Button" parent="Widget.Button">
    <item name="android:background">@android:drawable/btn_default_holo_dark</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    <item name="android:textColor">@android:color/primary_text_holo_dark</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:minWidth">64dip</item>
</style>

这篇关于怎样降低一个Android按钮对象中的文本两端内填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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