简体   繁体   English

Xamarin Android:如何将项目与操作栏的左侧对齐

[英]Xamarin Android: How to align items to the left of an Actionbar

I have a custom Actionbar and currently im trying to align the menu-icon to be on the left of the title.我有一个自定义操作栏,目前我正在尝试将菜单图标对齐到标题的左侧。 My actionbar我的操作栏

How can i achieve that?我怎样才能做到这一点?

Heres my "menu.xml":这是我的“menu.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/menu_OpenMenu"
  android:title="OpenMenu"
  android:icon="@drawable/Image_OpenMenu"
  app:showAsAction="always" />
<item 
  android:id="@+id/action_Search"
  android:title="Search"
  android:icon="@drawable/Image_Search"
  android:queryHint="Search..."
  app:showAsAction="always|collapseActionView"
  app:actionViewClass="android.support.v7.widget.SearchView"/>  
</menu>

And heres how i inflate it:这是我如何充气它:

public override bool OnCreateOptionsMenu(IMenu menu)
    {
        MenuInflater.Inflate(Resource.Menu.Top_Menus_Main, menu);

        // SearchView
        var item = menu.FindItem(Resource.Id.action_Search);
        var searchActionView = MenuItemCompat.GetActionView(item);
        searchView = searchActionView as Android.Support.V7.Widget.SearchView;

        return base.OnCreateOptionsMenu(menu);
    }

Action bar button are aligned at the right side you can not align them at the left side without custom view.操作栏按钮在右侧对齐,您不能在没有自定义视图的情况下将它们对齐到左侧。

check out this How to set two custom actionbar button in left and right in android?看看这个如何在android中的左右设置两个自定义操作栏按钮?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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