【发布时间】:2017-04-19 11:59:10
【问题描述】:
,这是我的xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Dashbored">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar">
</include>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tool_bar"
android:elevation="7dp"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/f_home_screen" />
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#0284fe"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:itemBackground="@drawable/drawer_backg"
app:itemIconTint="@color/drawer_item"
app:itemTextAppearance="@style/NavDrawerTextStyle"
app:itemTextColor="@color/windowBackground"
app:menu="@menu/main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
我想这样设置Item文本对齐中心
这是我的菜单 xml
<?xml version="1.0" encoding="utf-8"?><menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_inspec_rpt"
android:title="INSPECTION REPORTS"
/>
<item
android:id="@+id/nav_action"
android:title="ACTION ITEMS"
/>
<item
android:id="@+id/nav_appoint"
android:title="APPOINTMENTS" />
<item
android:id="@+id/nav_applst"
android:title="MAIN APPOINTMENTS" />
<item
android:id="@+id/nav_logout"
android:title="LOG OUT" />
</group>
我想获得像第二张图片这样的输出,请帮助我,我试图在 style.xml 中像这样给出样式,但我不知道如何对齐文本,我通过谷歌尝试了不同的方式,但是没有运气。 :(
<style name="NavDrawerTextStyle" parent="Base.TextAppearance.AppCompat">
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textSize">16dp</item>
<item name="android:fontFamily">serif</item>
<item name="android:textStyle">bold</item>
</style>
谢谢
【问题讨论】:
-
最后我找到了一个解决方案,我创建了一个 Listview 而不是菜单并提供文本对齐,它工作正常,谢谢
-
我在下面给出了我的解决方案,请检查一下
标签: android android-studio navigation-drawer android-xml