删除java(Android)中的按钮阴影

删除java(Android)中的按钮阴影,java,android,xml,Java,Android,Xml,我需要移除按钮上的阴影。因为它是用java(而不是xml)创建的,所以我看不到这样做的选项。我知道下面这行代码可以用在xml中 android:stateListAnimator="@null" 在java中尝试了如下相同的方法 myButton.setStateListAnimator(null); 但问题是,它只能在具有21个API或更高API的设备上工作。还有别的办法吗 android:background="@null" 我是说 myButton.setBackground(nul

我需要移除按钮上的阴影。因为它是用java(而不是xml)创建的,所以我看不到这样做的选项。我知道下面这行代码可以用在xml中

android:stateListAnimator="@null"
在java中尝试了如下相同的方法

myButton.setStateListAnimator(null);
但问题是,它只能在具有21个API或更高API的设备上工作。还有别的办法吗

android:background="@null"
我是说

myButton.setBackground(null);
编辑:其他可能性(对不起xml):

  • 将高程设置为0:

    mybutton.setElevation(0)

  • 将背景设置为透明:

    android:background=“@android:color/transparent”

    检查:

  • 将样式设置为按钮:

        <Button
         ...
         style="?android:attr/borderlessButtonStyle"
          ....
         /> 
    

  • 您也可以访问:

    使用
    按钮。设置阴影层(浮动半径、浮动dx、浮动dy、int-Color)
    并通过阴影将
    半径设置为
    0

    您指的是高程吗?如果是这样的话,在低于21的设备中不存在标高。因此,对于运行myButton.setBackground(0)的设备,按钮上没有标高;我需要在Java文件中完成它。已尝试myButton.setBackground(null),但未成功。请尝试以下操作:
    Button button = new Button(getApplicationContext(), null, android.R.attr
            .borderlessButtonStyle);
    button = (Button) findViewById(R.id.buttonEndTime);