简体   繁体   中英

Navigation Bar isn't wide enough

I have a problem. I created a menu_bar.axml with the following code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="75dp"
    android:weightSum="100"
    android:background="#071c3f">
    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="15"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/StatusImageLayout"
        android:clickable="false">
        <ImageView
            android:src="@drawable/disconnected"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/imgConnectionStatus"
            android:foregroundGravity="center_horizontal"
            android:layout_marginLeft="1dp" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="70"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/ProjectNameLayout" >
        <TextView
            android:text="Project Name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/txtProjectName"
            android:gravity="center"
            android:textStyle="bold"
            android:textSize="30dp"
            android:textColor="#ffffffff" 
            android:layout_marginLeft="3dp"
            android:layout_marginRight="3dp"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="15"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/SettingsButtonLayout" >
        <ImageView
            android:src="@drawable/settings"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/imgSettingsLogo"
            android:foregroundGravity="center_horizontal"
            android:layout_marginRight="1dp"/>
    </LinearLayout>
</LinearLayout>

Then I created a custom style like this:

<resources>
  <style name="MyAppTheme">
          parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MenuBar</item>
  </style>

  <style name="MenuBar"
         parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:height">75dp</item>
    <item name="android:displayOptions"></item>
    <item name="android:background">#00000000</item>
  </style>
</resources>

And finally in my MainActivity.cs I set these lines in the OnCreate()

ActionBar.SetCustomView(Resource.Layout.menu_bar);
ActionBar.SetDisplayShowCustomEnabled(true);

Now the Menubar pops up like I want it (almost), but the Navigation bar isn't wide enough for the screen. I have no idea where it comes from and I can't figure out how to get rid of it. Here is the link for my screen:

我的应用程序屏幕

Any ideas how to fix this or what I am doing wrong?

you could see source code in the actionbar (caused by the latest changes to the ActionBar in the recent appcompat-v7 update)

<style name="Base.Widget.AppCompat.Toolbar" parent="android:Widget"> 
 <item name="titleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Title</item> 
 <item name="subtitleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle</item> 
 <item name="android:minHeight">?attr/actionBarSize</item> 
 <item name="titleMargins">4dp</item> 
 <item name="maxButtonHeight">56dp</item> 
 <item name="collapseIcon">?attr/homeAsUpIndicator</item> 
 <item name="collapseContentDescription">@string/abc_toolbar_collapse_description</item> 
 <item name="contentInsetStart">16dp</item> 
</style>

<item name="contentInsetStart">16dp</item> the contentInsetStart property is what causes the custom ActionBar to not fill completely

and beginning with Android L (API level 21), the action bar may be represented by any Toolbar widget within the application layout ,so the simple solution is as follows:

ActionBar.SetCustomView(Resource.Layout.menu_bar);
ActionBar.SetDisplayShowCustomEnabled(true);
((Toolbar)ActionBar.CustomView.Parent).SetContentInsetsAbsolute(0,0);//add this line to remove the left margin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM