Xamarin - 在操作栏中添加标题和按钮
Xamarin - Add title and button in action bar
我正在使用 xamarin.form(便携式)有两个项目 android 和 ios。
我想在操作栏中添加标题,该标题会根据详细信息页面而变化还想在操作栏右侧添加一个按钮
我在下面参考link
https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage
这 link 帮助我创建导航页面。但无法在操作栏中添加标题和按钮
下面是我想要的操作栏图片。 Payment是一个title,可以根据详情页改变,右边的“+”是button
请建议我如何使用 xamarin 表单(便携式)在操作栏中添加标题和按钮
您需要创建页面,因为没有任何其他选项可以在不使用主详细信息页面中的工具栏项的情况下添加加号
以下是一些示例代码
public class TodoListPageCS : ContentPage
{
private ToolbarItem _saveAddToolBarItem;
public TodoListPageCS ()
{
Title = "Page Name";
_saveAddToolBarItem = new ToolbarItem()
{ Text = "Save"};
ToolbarItems.Add(_saveAddToolBarItem);
_saveAddToolBarItem.Clicked += _saveAddToolBarItem_Clicked;
Content = new StackLayout {
Children = {
new Label {
Text = "Todo list data goes here",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
}
}
};
}
private void _saveAddToolBarItem_Clicked(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
}
否则,您需要创建自己的自定义基页而不是内容页
要更改工具栏颜色,请参考以下内容link:
https://forums.xamarin.com/discussion/44586/navigationbar-background-image-renderer-android
希望此代码对您有所帮助
更改工具栏颜色的方法:
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) {
BarBackgroundColor = Color.FromHex("#42a990"),
BarTextColor = Color.White,
};
我正在使用 xamarin.form(便携式)有两个项目 android 和 ios。
我想在操作栏中添加标题,该标题会根据详细信息页面而变化还想在操作栏右侧添加一个按钮
我在下面参考link
https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage
这 link 帮助我创建导航页面。但无法在操作栏中添加标题和按钮
下面是我想要的操作栏图片。 Payment是一个title,可以根据详情页改变,右边的“+”是button
请建议我如何使用 xamarin 表单(便携式)在操作栏中添加标题和按钮
您需要创建页面,因为没有任何其他选项可以在不使用主详细信息页面中的工具栏项的情况下添加加号
以下是一些示例代码
public class TodoListPageCS : ContentPage
{
private ToolbarItem _saveAddToolBarItem;
public TodoListPageCS ()
{
Title = "Page Name";
_saveAddToolBarItem = new ToolbarItem()
{ Text = "Save"};
ToolbarItems.Add(_saveAddToolBarItem);
_saveAddToolBarItem.Clicked += _saveAddToolBarItem_Clicked;
Content = new StackLayout {
Children = {
new Label {
Text = "Todo list data goes here",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
}
}
};
}
private void _saveAddToolBarItem_Clicked(object sender, System.EventArgs e)
{
throw new System.NotImplementedException();
}
}
否则,您需要创建自己的自定义基页而不是内容页
要更改工具栏颜色,请参考以下内容link: https://forums.xamarin.com/discussion/44586/navigationbar-background-image-renderer-android
更改工具栏颜色的方法:
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) {
BarBackgroundColor = Color.FromHex("#42a990"),
BarTextColor = Color.White,
};