在按钮视图中删除的文字填充视图、按钮、文字

2023-09-07 12:34:46 作者:要拽就喝敌敌畏

我想删除填充文本周围的按钮来查看。 第一屏幕截图是结果我会实现的,第二个是在现有技术的状态。

当然,我已经定义了一个自定义绘制获得按钮外观。但即使我设置填充属性来0dp的结果不会改变。

任何建议,请?

修改 这里是按钮的XML code

 <按钮
        机器人:ID =@ + ID / btnCancel
        风格=@风格/ dark_header_button
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_marginLeft =10dp
        机器人:layout_height =WRAP_CONTENT
        机器人:includeFontPadding =假
        机器人:填充=0dp
        机器人:layout_alignParentLeft =真
        机器人:layout_centerVertical =真
        机器人:文本=@安卓串/取消/>
 

下面是样式xml文件:

 <样式名称=dark_header_button>
    <项目名称=机器人:背景> @可绘制/ bkg_dark_header_button< /项目>
    <项目名称=机器人:shadowDy> -1 LT; /项目>
    <项目名称=安卓则shadowColor>#000000< /项目>
    <项目名称=机器人:shadowRadius> 1< /项目>
    <项目名称=机器人:TEXTSIZE> 14sp< /项目>
    <项目名称=机器人:文字颜色>#FFFFFF< /项目>
< /风格>
 
3dMax怎么制作圆桌布模型

和这里是绘制xml文件:

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

<项目的android:STATE_ pressed =真正的>
    <形状>

        <边角机器人:半径=10dp/>

        <梯度
            机器人:角=90
            机器人:endColor =#060606
            机器人:startColor =#707070
            机器人:TYPE =线性/>

    < /形状>
< /项目>
<项目>
    <形状>

        <边角机器人:半径=10dp/>

        <梯度
            机器人:角=90
            机器人:endColor =#707070
            机器人:startColor =#060606
            机器人:TYPE =线性/>

        <中风
            机器人:宽=0.5dp
            机器人:颜色=#2b2b2b/>

    < /形状>
< /项目>


< /选择器>
 

解决方案

有没有必要填充按钮文字,它的按钮默认中心。 我认为你正在使用的机器人:主题=@安卓风格/ Theme.Black.NoTitleBar清单文件中,请删除它答使用本机应用程序的主题,并尝试了它

I would like to remove the padding around text in Button view. The first screenshot is the result I would achieve, and the second one is the state of the art.

Of course, I have defined a custom drawable to get the button appearance. But even if I set the padding attribute to 0dp the result does not change.

Any suggestion, please?

EDIT Here is the xml code of the button

<Button
        android:id="@+id/btnCancel"
        style="@style/dark_header_button"
        android:layout_width="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_height="wrap_content"
        android:includeFontPadding="false"
        android:padding="0dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@android:string/cancel" />

Here is the style xml file:

<style name="dark_header_button">
    <item name="android:background">@drawable/bkg_dark_header_button</item>
    <item name="android:shadowDy">-1</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowRadius">1</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">#ffffff</item>
</style>

and here is the drawable xml file:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true">
    <shape>

        <corners android:radius="10dp" />

        <gradient 
            android:angle="90" 
            android:endColor="#060606"
            android:startColor="#707070"
            android:type="linear" />

    </shape>
</item>
<item>
    <shape>

        <corners android:radius="10dp" />

        <gradient 
            android:angle="90" 
            android:endColor="#707070" 
            android:startColor="#060606" 
            android:type="linear" />

        <stroke 
            android:width="0.5dp" 
            android:color="#2b2b2b" />

    </shape>
</item>


</selector>

解决方案

Button text having no need padding, it default centre of the button. I think you are using the android:theme="@android:style/Theme.Black.NoTitleBar" in the manifest file, please remove it ans use native app Theme and try the it.