工具栏上的波纹效果被切断
Ripple effect on Toolbar cut off
我在我的应用程序中使用 Toolbar
并用菜单对其进行扩充。
我这里有一个问题,因为波纹效果自动添加到按钮,但最左边的按钮的波纹效果被菜单区域的边界切断。
您可以看到波纹扩大,但随后在左侧关闭。
知道如何解决这个问题吗?
最简单的方法是像简单视图一样在工具栏中添加按钮,例如:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="ICON HERE"
android:background="@null"/>
</android.support.v7.widget.Toolbar>
android:background="@null"
它将禁用按钮的涟漪效果
我也遇到过这个,在玩了之后我发现我们的自定义 ThemeOverlay
设置了背景。
尝试从您的工具栏样式和主题中删除 android:background
。
看下面我注释掉了:<item name="android:background">@color/toolbar</item>
。之后它按预期工作。
<style name="MyTheme.Overlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="android:windowBackground">@color/background</item>
<!--<item name="android:background">@color/toolbar</item>-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/toolbar</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/toolbar</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
</style>
我在我的应用程序中使用 Toolbar
并用菜单对其进行扩充。
我这里有一个问题,因为波纹效果自动添加到按钮,但最左边的按钮的波纹效果被菜单区域的边界切断。
您可以看到波纹扩大,但随后在左侧关闭。
知道如何解决这个问题吗?
最简单的方法是像简单视图一样在工具栏中添加按钮,例如:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="ICON HERE"
android:background="@null"/>
</android.support.v7.widget.Toolbar>
android:background="@null"
它将禁用按钮的涟漪效果
我也遇到过这个,在玩了之后我发现我们的自定义 ThemeOverlay
设置了背景。
尝试从您的工具栏样式和主题中删除 android:background
。
看下面我注释掉了:<item name="android:background">@color/toolbar</item>
。之后它按预期工作。
<style name="MyTheme.Overlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="android:windowBackground">@color/background</item>
<!--<item name="android:background">@color/toolbar</item>-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/toolbar</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/toolbar</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
</style>