如何移除按钮底部边框。

huangapple go评论104阅读模式
英文:

how can I remove button bottom border

问题

I want to use custom background on android button without any border and with radius only on top of the button and I make the drawable like that but the problem I got a gray line in the bottom of the button how I can remove it I already using style="@android:style/Widget.Holo.Button.Borderless" but it didn't make anything

我想在Android按钮上使用自定义背景,没有任何边框,只在按钮顶部使用半径。我已经创建了这样的可绘制对象,但问题是我得到了按钮底部的灰色线条,我如何移除它?我已经使用style="@android:style/Widget.Holo.Button.Borderless",但它没有产生任何效果。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/turquoise" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <corners
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="0dp"
                android:topLeftRadius="14dp"
                android:topRightRadius="14dp" />
            <solid android:color="@color/white" />
            <size android:height="60dp" />
        </shape>
    </item>
</layer-list>

and here is the button used in the layout

以下是布局中使用的按钮:

<Button
      android:id="@+id/btn_bg"
      style="@android:style/Widget.Holo.Button.Borderless"
      android:layout_width="match_parent"
      android:layout_height="60dp"
      android:clickable="false"
      android:background="@drawable/custom_bg_white"
      android:textSize="14sp"
      android:visibility="visible" />

<details>
<summary>英文:</summary>

[![enter image description here][1]][1]
I want to use custom background on android button without any border and with radius only on top of the button and I make the drawable like that but the problem I got a gray line in the bottom of the button how I can remove it I already using            style=&quot;@android:style/Widget.Holo.Button.Borderless&quot; but it didn&#39;t make anything


    &lt;layer-list xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &lt;item&gt;
        &lt;shape android:shape=&quot;rectangle&quot;&gt;
            &lt;solid android:color=&quot;@color/turquoise&quot; /&gt;
        &lt;/shape&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;shape android:shape=&quot;rectangle&quot;&gt;
            &lt;corners
                android:bottomLeftRadius=&quot;0dp&quot;
                android:bottomRightRadius=&quot;0dp&quot;
                android:topLeftRadius=&quot;14dp&quot;
                android:topRightRadius=&quot;14dp&quot; /&gt;
            &lt;solid android:color=&quot;@color/white&quot; /&gt;
            &lt;size android:height=&quot;60dp&quot; /&gt;
        &lt;/shape&gt;
    &lt;/item&gt;
&lt;/layer-list&gt;

and here is the button used in the layout 

    &lt;Button
          android:id=&quot;@+id/btn_bg&quot;
          style=&quot;@android:style/Widget.Holo.Button.Borderless&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;60dp&quot;
          android:clickable=&quot;false&quot;
          android:background=&quot;@drawable/custom_bg_white&quot;
          android:textSize=&quot;14sp&quot;
          android:visibility=&quot;visible&quot; /&gt;


  [1]: https://i.stack.imgur.com/9ldcS.png

</details>


# 答案1
**得分**: 1

这条灰线不是边框,而是按钮样式产生的高度。如果不想要它,请设置`android:elevation=0dp`并设置`android:stateListAnimator="@null"`。

<details>
<summary>英文:</summary>

this gray line is not border it&#39;s the elevation that is made by the button style if you don&#39;t want it set `android:elevation=0dp` and set ` android:stateListAnimator=&quot;@null&quot;`

</details>



# 答案2
**得分**: 0

Replace your drawable file with below code and check

```xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <corners
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="0dp"
                android:topLeftRadius="14dp"
                android:topRightRadius="14dp" />
            <solid android:color="@color/white" />
            <size android:height="60dp" />
        </shape>
    </item>
</layer-list>

or Share your full xml layout file code

英文:

Replace your drawable file with below code and check

   &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;layer-list xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &lt;item&gt;
        &lt;shape android:shape=&quot;rectangle&quot;&gt;
            &lt;solid android:color=&quot;@android:color/transparent&quot; /&gt;
        &lt;/shape&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;shape android:shape=&quot;rectangle&quot;&gt;
            &lt;corners
                android:bottomLeftRadius=&quot;0dp&quot;
                android:bottomRightRadius=&quot;0dp&quot;
                android:topLeftRadius=&quot;14dp&quot;
                android:topRightRadius=&quot;14dp&quot; /&gt;
            &lt;solid android:color=&quot;@color/white&quot; /&gt;
            &lt;size android:height=&quot;60dp&quot; /&gt;
        &lt;/shape&gt;
    &lt;/item&gt;
    &lt;/layer-list&gt;

or Share your full xml layout file code

huangapple
  • 本文由 发表于 2020年1月6日 17:42:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定