这个问题似乎经常被问到,但是查看各种答案(非 Xamarin),其中没有一个可以使用Xamarin
......
在我的活动中,我尝试了各种形式的做事:
public override void OnWindowFocusChanged( bool hasFocus ) {
base.OnWindowFocusChanged( hasFocus );
if ( hasFocus ) {
var uiOptions =
SystemUiFlags.HideNavigation |
SystemUiFlags.LayoutHideNavigation |
SystemUiFlags.LayoutFullscreen |
SystemUiFlags.Fullscreen |
SystemUiFlags.LayoutStable |
SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility) uiOptions;
}
}
我也在活动中尝试过这个OnCreate()
。似乎没有任何效果。
我已阅读: https ://developer.android.com/training/system-ui/immersive.html https://cmsdk.com/android/hide-navigation-bar-android-xamarin.html http://codegur。 com/28394281/in-xamarin-android-how-can-i-hide-the-navigation-bar
活动.cs:
using Android.App;
using Android.Graphics;
using Android.OS;
using Android.Support.V4.Content;
using Android.Views;
using Android.Widget;
using Calligraphy;
using Dictionary.Fragments;
using Dictionary.Logic.Translation;
using Newtonsoft.Json;
namespace Dictionary.Activities {
[Activity( MainLauncher = true )]
public class MainActivity: Activity {
protected override void OnCreate( Bundle bundle ) {
base.OnCreate( bundle );
SetContentView( Resource.Layout.Main );
SetToolbar();
SetStatusBarColor();
ShowSearchFragment();
}
public override void OnWindowFocusChanged( bool hasFocus ) {
base.OnWindowFocusChanged( hasFocus );
if ( hasFocus ) {
var uiOptions =
SystemUiFlags.HideNavigation |
SystemUiFlags.LayoutHideNavigation |
SystemUiFlags.LayoutFullscreen |
SystemUiFlags.Fullscreen |
SystemUiFlags.LayoutStable |
SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility) uiOptions;
}
}
public override bool OnCreateOptionsMenu( IMenu menu ) {
MenuInflater.Inflate( Resource.Menu.Toolbar, menu );
return base.OnCreateOptionsMenu( menu );
}
protected override void AttachBaseContext( Android.Content.Context @base ) {
base.AttachBaseContext( CalligraphyContextWrapper.Wrap( @base ) );
}
private void SetStatusBarColor() {
Window.AddFlags( WindowManagerFlags.DrawsSystemBarBackgrounds );
Window.SetStatusBarColor( new Color( ContextCompat.GetColor( this, Resource.Color.PrimaryColorDark ) ) );
}
private void SetToolbar() {
var toolbar = FindViewById<Toolbar>( Resource.Id.toolbar );
SetActionBar( toolbar );
ActionBar.Title = GetString( Resource.String.AppName );
}
private void ShowSearchFragment() {
var searchFragment = new SearchFragment();
searchFragment.TranslationSelected += OnTranslationSelected;
var fragTrans = FragmentManager.BeginTransaction();
fragTrans.Add( Resource.Id.fragHolder, searchFragment );
fragTrans.Commit();
}
}
}
发现问题:
我的搜索片段中的这个编辑框导致键盘显示,打破了全屏模式,即使键盘消失了,全屏也不会返回。
<EditText android:id="@+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#FFF"
android:gravity="center"
android:hint="@string/SearchHint"
android:imeOptions="flagNoExtractUi|actionDone"
android:inputType="textNoSuggestions"
android:singleLine="true"
android:textColorHint="#ABABAB"
android:textSize="18sp"
fontPath="Fonts/amiri-regular.ttf"
android:textCursorDrawable="@drawable/cursor"/>