Xamarin Android 导航栏Xamarin.Android Navigation Bar
05/01/2017
本文内容
Android 4 引入了一个名为 " 导航栏" 的新的系统用户界面功能,该功能可在不包含 Home、 Back和 Menu硬件按钮的设备上提供导航控件。Android 4 introduced a new system user interface feature called a Navigation Bar, which provides navigation controls on devices that don't include hardware buttons for Home, Back, and Menu.
以下屏幕截图显示了结点质数设备的导航栏:The following screenshot shows the Navigation Bar from a Nexus Prime device:
可以使用多个新标志来控制导航栏及其控件的可见性,以及 Android 3 中引入的系统栏的可见性。Several new flags are available that control the visibility of the Navigation Bar and its controls, as well as the visibility of the System Bar that was introduced in Android 3. 标志在类中定义,如下所示 Android.View.View :The flags are defined in the Android.View.View class and are listed below:
SystemUiFlagVisible–使导航栏可见。SystemUiFlagVisible – Makes the Navigation Bar visible.
SystemUiFlagLowProfile–缩小导航栏中的控件。SystemUiFlagLowProfile – Dims out controls in the Navigation Bar.
SystemUiFlagHideNavigation–隐藏导航栏。SystemUiFlagHideNavigation – Hides the Navigation Bar.
可以通过设置属性将这些标志应用于视图层次结构中的任何视图 SystemUiVisibility 。These flags can be applied to any view in the view hierarchy by setting the SystemUiVisibility property. 如果有多个视图设置了此属性,系统会将它们与或操作组合在一起,并应用它们,只要设置了标志的窗口保持焦点。If multiple views have this property set, the system combines them with an OR operation and applies them so long as the window in which the flags are set retains focus. 删除视图时,还将删除其设置的所有标志。When you remove a view, any flags it has set will also be removed.
下面的示例演示一个简单的应用程序,其中单击任意按钮将更改 SystemUiVisibility :The following example shows a simple application where clicking any of the buttons changes the SystemUiVisibility:
用于更改的代码 SystemUiVisibility 将 TextView 从每个按钮的单击事件处理程序中设置的属性,如下所示:The code to change the SystemUiVisibility sets the property on a TextView from each button's click event handler as shown below:
var tv = FindViewById (Resource.Id.systemUiFlagTextView);
var lowProfileButton = FindViewById(Resource.Id.lowProfileButton);
var hideNavButton = FindViewById (Resource.Id.hideNavigation);
var visibleButton = FindViewById (Resource.Id.visibleButton);
lowProfileButton.Click += delegate {
tv.SystemUiVisibility =
(StatusBarVisibility)View.SystemUiFlagLowProfile;
};
hideNavButton.Click += delegate {
tv.SystemUiVisibility =
(StatusBarVisibility)View.SystemUiFlagHideNavigation;
};
visibleButton.Click += delegate {
tv.SystemUiVisibility = (StatusBarVisibility)View.SystemUiFlagVisible;
}
此外,更改还会 SystemUiVisibility 引发 SystemUiVisibilityChange 事件。Also, a SystemUiVisibility change raises a SystemUiVisibilityChange event. 与设置属性一样 SystemUiVisibility , SystemUiVisibilityChange 可为层次结构中的任何视图注册事件的处理程序。Just like setting the SystemUiVisibility property, a handler for the SystemUiVisibilityChange event can be registered for any view in the hierarchy. 例如,下面的代码使用 TextView 实例注册事件:For example, the code below uses the TextView instance to register for the event:
tv.SystemUiVisibilityChange +=
delegate(object sender, View.SystemUiVisibilityChangeEventArgs e) {
tv.Text = String.Format ("Visibility = {0}", e.Visibility);
};
相关链接Related Links