如何从ToggleButton中删除材质阴影?

时间:2015-02-12 10:52:31

标签: android material-design

今天我遇到了一个问题:

在我的自定义布局中,在此LinearLayout内的TextView之后有一个带有灰色背景的LinearLayout和ToggleButton。 切换按钮具有透明背景。 但在android Lollipop这里是不必要的影子。 我试过了elevation = 0dp属性。但这确实解决了我的问题。

当我设置api = 21

时会发生这种情况

enter image description here

在旧的apis上发生这种情况< 21

enter image description here

以下是示例布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:orientation="horizontal"
    android:background="@color/grey_light">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0123" />

    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:button="@android:color/transparent" />
</LinearLayout>

如何删除此影子?

2 个答案:

答案 0 :(得分:24)

尝试使用style="@android:style/Widget.Holo.Button.Borderless

将小部件更改为appcompat(或您正在使用的任何内容)。

我正在使用它:

style="?android:attr/borderlessButtonStyle"

答案 1 :(得分:2)

ToggleButton使用随附的状态列表动画器管理其高程和translationZ。您可以通过设置禁用它:

android:stateListAnimator="@null"

或通过提供自己的选择器来处理这些值:

android:stateListAnimator="@drawable/my_selector"
相关问题