Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改导航页面上的菜单栏图标_Android_Xamarin.forms_Master Detail - Fatal编程技术网

Android 更改导航页面上的菜单栏图标

Android 更改导航页面上的菜单栏图标,android,xamarin.forms,master-detail,Android,Xamarin.forms,Master Detail,我正在拼命尝试更改我的Xamarin表单应用程序上的图标颜色。我以为这个汉堡菜单是文本,但我现在似乎根本无法更改它。这是图像吗?我发现了一个slideout.png图像,但对该图像的任何编辑都不会显示在应用程序中。这个汉堡菜单图标是从哪里来的 第页: [XamlCompilation(XamlCompilationOptions.Compile)] 公共部分类登录页:MasterDetailPage { 公众登入网页() { 初始化组件(); MasterPage.ListView.ItemSe

我正在拼命尝试更改我的Xamarin表单应用程序上的图标颜色。我以为这个汉堡菜单是文本,但我现在似乎根本无法更改它。这是图像吗?我发现了一个slideout.png图像,但对该图像的任何编辑都不会显示在应用程序中。这个汉堡菜单图标是从哪里来的

第页:

[XamlCompilation(XamlCompilationOptions.Compile)]
公共部分类登录页:MasterDetailPage
{
公众登入网页()
{
初始化组件();
MasterPage.ListView.ItemSelected+=ListView\u ItemSelected;
}
public void ListView\u ItemSelected(对象发送者,SelectedItemChangedEventArgs e)
{
var item=e.选择editem作为登陆页面菜单项;
如果(项==null)
返回;
var page=(page)Activator.CreateInstance(item.TargetType);
page.Title=项目.Title;
详细信息=新导航页面(第页);
MasterPage.ListView.SelectedItem=null;
IsPresented=假;
}
}
大师:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LandingPageMaster : ContentPage
{
    public LandingPageMasterViewModel Vm { get; private set; }
    public ListView ListView => ListViewMenuItems;
    public LandingPageMaster()
    {
        InitializeComponent();
        Vm = new LandingPageMasterViewModel();
        BindingContext = Vm;
    }

    protected override void OnAppearing()
    {
        ListViewMenuItems.SelectedItem = Vm.MenuItems[0];
    }
    public class LandingPageMasterViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<LandingPageMenuItem> _menuItems;

        public ObservableCollection<LandingPageMenuItem> MenuItems
        {
            get
            {
                return _menuItems;
            }
            set
            {
                _menuItems = value;
                OnPropertyChanged();
            }
        }

        public LandingPageMasterViewModel()
        {
            ObservableCollection<LandingPageMenuItem> items = new ObservableCollection<LandingPageMenuItem>();
            items.Add(new LandingPageMenuItem { Title = "OCR" });
            MenuItems = items;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Test.LandingPageMaster" Title="">
    <StackLayout>
        <ListView x:Name="ListViewMenuItems" SeparatorVisibility="None" HasUnevenRows="True" ItemsSource="{Binding MenuItems}">
            <ListView.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <Label Grid.Column = "0" Grid.Row="0" Text=" " />
                </Grid>
            </ListView.Header>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
                            <Label VerticalOptions="FillAndExpand" VerticalTextAlignment="Center" Text="{Binding Title}" FontSize="Medium" />
                            <Label VerticalOptions="FillAndExpand" VerticalTextAlignment="Center" Text="{Binding Subtitle}" FontSize="Small" />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>
[XamlCompilation(XamlCompilationOptions.Compile)]
公共部分类LandingPageMaster:ContentPage
{
公共登录PageMasterViewModel Vm{get;private set;}
公共ListView ListView=>ListViewMenuItems;
公共登录页面管理器()
{
初始化组件();
Vm=新的登录页面主视图模型();
BindingContext=Vm;
}
出现时受保护的覆盖无效()
{
ListViewMenuItems.SelectedItem=Vm.MenuItems[0];
}
公共类登录页面主视图模型:INotifyPropertyChanged
{
私人可观测采集菜单;
公共可观测集合菜单项
{
得到
{
返回菜单项;
}
设置
{
_menuItems=值;
OnPropertyChanged();
}
}
公共登录页面主视图模型()
{
ObservableCollection items=新的ObservableCollection();
添加(新登陆页面菜单项{Title=“OCR”});
菜单项=项目;
}
公共事件属性更改事件处理程序属性更改;
void OnPropertyChanged([CallerMemberName]string propertyName=”“)=>PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(propertyName));
}
}
详情:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LandingPageDetail : ContentPage
{
    public LandingPageDetail()
    {
        InitializeComponent();
    }
}


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Test.LandingPageDetail" Title="Detail">
    <StackLayout Padding="10">
        <Label Text="This is a detail page" />
    </StackLayout>
</ContentPage>
[XamlCompilation(XamlCompilationOptions.Compile)]
公共部分类登录页面详细信息:ContentPage
{
公共着陆页面详细信息()
{
初始化组件();
}
}

在Android上,汉堡包图形和附带的动画由Android操作系统提供,并不关心主细节中定义的图标,尽管该图标将在iOS/UWP上使用

它可能会被覆盖,尽管我没有必要这样做,所以我无法在这方面提供帮助


如果你只是在更改了颜色之后,那么更改标题栏的android主题文本颜色,这也会更改汉堡包的颜色,据我所知。

这是android平台中的一个
ImageButton
。因此,您可以更改此汉堡按钮的图像源

您可以创建自定义的
MasterDetailPage
使用,例如,在渲染器中:

public class MyMasterDetailRenderer : MasterDetailPageRenderer
{
    protected override void OnLayout(bool changed, int l, int t, int r, int b)
    {
        base.OnLayout(changed, l, t, r, b);
        var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        for (var i = 0; i < toolbar.ChildCount; i++)
        {
            var imageButton = toolbar.GetChildAt(i) as ImageButton;

            var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
            if (drawerArrow == null)
                continue;

            imageButton.SetImageDrawable(Forms.Context.GetDrawable(Resource.Drawable.hamburger));
        }
    }
}
公共类MyMasterDetailRenderer:MasterDetailPageRenderer
{
受保护覆盖仅限无效布局(布尔值已更改、整数l、整数t、整数r、整数b)
{
仅基础布局(已更改,l、t、r、b);
var-toolbar=findviewbyd(Resource.Id.toolbar);
对于(var i=0;i
谢谢您的回答。你能解释一下我将如何使用Android styles.xml改变颜色吗?嗨,这很有效。然而,我注意到这种方法有一个小问题。如果我如上所述更改汉堡包菜单,则返回箭头也会更改为汉堡包图标。我认为在循环中,应该有一种方法来识别工具栏项是否是汉堡图像,然后才对其进行更改,否则应该忽略它。我无法解决这个问题。任何想法。谢谢
public class MyMasterDetailRenderer : MasterDetailPageRenderer
{
    protected override void OnLayout(bool changed, int l, int t, int r, int b)
    {
        base.OnLayout(changed, l, t, r, b);
        var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        for (var i = 0; i < toolbar.ChildCount; i++)
        {
            var imageButton = toolbar.GetChildAt(i) as ImageButton;

            var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
            if (drawerArrow == null)
                continue;

            imageButton.SetImageDrawable(Forms.Context.GetDrawable(Resource.Drawable.hamburger));
        }
    }
}