将TextView添加到工具栏的元素
我制作了一个材质设计工具栏.菜单项包括一个购物车.我希望在显示购物车图标的同时显示一个数字,以指示购物车中存在的物品数量.
I have made a material design toolbar. The menu item includes a cart. I want a number to be shown along with the cart icon indicating the number of items present in the cart.
toolbar.xml
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Light"
android:id="@+id/tool_bar"
android:elevation="6dp">
menu_cart.xml
menu_cart.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_cart" android:icon="@drawable/bag"
android:title="Cart"
android:orderInCategory="100" app:showAsAction="always" />
</menu>
也许在购物车图标顶部应该可以看到该文本视图.不能作为购物车图标旁边的文本视图.
The textview should be visible on top of the cart icon hiding it a bit,maybe. Not as a textview beside the cart icon.
类似的东西-
首先,请学习如何创建自己的自定义工具栏.
First, please learn how to create your own customized toolbar.
搜索如下主题:然后,您可以如下所示创建工具栏;-)
Then you can create your toolbar as below ;-)
这是您想要的工具栏的一个示例
Here is an example of your wannabe toolbar
<ImageView
android:id="@+id/shopping_bag"
android:layout_width="44dp"
android:layout_height="44dp"
android:src="@drawable/bag"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"></ImageView>
<ImageView
android:id="@+id/arrow"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:src="@drawable/usability_bidirectionality_guidelines_when3"
android:layout_alignParentRight="true"></ImageView>
<ImageView
android:id="@+id/number"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/one"
android:layout_alignTop="@+id/shopping_bag"
android:layout_alignRight="@+id/shopping_bag"/>
</RelativeLayout>
它看起来像:
要获得更好的外观,请找到受Material Design启发的图标.
To have a better look, find Material Design inspired icons.
希望有帮助