actionLayout 在导航抽屉中的定位 [英] Positioning of actionLayout in navigation drawer

查看:13
本文介绍了actionLayout 在导航抽屉中的定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置:

尽管样式设置了重力,气泡仍显示在顶部.

如何将 actionLayout 放置在菜单项的中间?

解决方案

我无意中解决了这个问题.

我不得不将 TextView 放入容器中:

<文本视图android:id="@+id/counterView"风格=@风格/泡泡"android:layout_width="26dp"android:layout_height="26dp"机器人:文本=55"/></LinearLayout>

现在计数器显示在菜单项的正中间!

<小时>

更新

计数器更改代码:

TextView view = (TextView) drawer.getMenu().findItem(R.id.counter_item).getActionView().findViewById(R.id.counterView);view.setText("" + count);

I have the following setup:

<android.support.design.widget.NavigationView
    style="@style/NavigationView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:itemTextAppearance="@style/DrawerTextAppearance"
    app:menu="@menu/drawer"/>

menu/drawer.xml

<menu>    
    <item
        android:id="@+id/messages_item"
        android:icon="@drawable/ic_notifications_neg"
        app:actionLayout="@layout/counter"
        android:title="@string/message_center"/>

    <item
        android:id="@+id/search_item"
        android:icon="@drawable/ic_search_neg"
        android:title="@string/search"/>
</menu>

layout/counter.xml

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="26dp"
    android:layout_height="26dp"
    android:text="55"
    style="@style/Bubble"/>

style:

<style name="Bubble" parent="android:Widget.TextView">
    <item name="android:gravity">center</item>
    <item name="android:layout_gravity">center_vertical</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/bubble</item>
</style>

this produces the following result:

the bubble is shown at the top despite style's gravity setting.

How can I position the actionLayout in the middle of a menu item?

解决方案

I managed to solve the problem by accident.

I had to put the TextView inside a container:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/counterView"
        style="@style/Bubble"
        android:layout_width="26dp"
        android:layout_height="26dp"
        android:text="55"/>
</LinearLayout>

Now the counter is shown right in the middle of the menu item!


UPDATE

Counter changing code:

TextView view = (TextView) drawer.getMenu().findItem(R.id.counter_item).getActionView().findViewById(R.id.counterView);
view.setText("" + count);

这篇关于actionLayout 在导航抽屉中的定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆