删除按钮单击时的阴影

时间:2018-05-21 05:55:26

标签: android

我在我的应用程序中创建了一个按钮列表,并将背景设置为椭圆形。按下每个按钮,我看到一个矩形的阴影,我该如何删除阴影。

请查看以下屏幕截图:

Button shawdow

以下是XML中的按钮:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:visibility="visible">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawableLeft="@drawable/ic_compose"
        android:background="@drawable/roundedbutton"
        android:text="@string/ver"
        android:textSize="20sp"
        android:textColor="@color/blacktext" />

</LinearLayout>

圆形按钮drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FFFFFF"
        android:endColor="@color/white"
        android:angle="270" />
    <corners android:radius="55dp" />
    <stroke android:width="5px" android:color="@color/buttoncolor" />
</shape>

3 个答案:

答案 0 :(得分:0)

将此添加到按钮样式:

shadowOffset: { height: 0, width: 0 },
shadowOpacity: 0,
elevation:0

它应该删除android

上的按钮阴影

答案 1 :(得分:0)

您需要在背景中添加一个选择器,例如

<item android:state_selected="true">
// if you want to change the color or any thing on press of the button, do that here
    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#FFFFFF"
            android:endColor="@color/white"
            android:angle="270" />
        <corners android:radius="55dp" />
        <stroke android:width="5px" android:color="@color/buttoncolor" />
    </shape>
</item>

<item >
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#FFFFFF"
            android:endColor="@color/white"
            android:angle="270" />
        <corners android:radius="55dp" />
        <stroke android:width="5px" android:color="@color/buttoncolor" />
    </shape>
</item>

答案 2 :(得分:0)

在按钮中尝试此操作

android:stateListAnimator

style="?android:attr/borderlessButtonStyle" 适用于api&gt; = 21.如果 min sdk&lt; 21 ,您可以使用

//
// GET: /login
[OutputCache(NoStore = true, Location = System.Web.UI.OutputCacheLocation.None)]
public ActionResult Login()
{
    return View();
}

//
// POST: /login
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

    if (!ModelState.IsValid)
    {
        return View(model);
    }
    //etc...