gpt4 book ai didi

android - 如何在 xamarin android 中隐藏导航栏?

转载 作者:搜寻专家 更新时间:2023-11-01 08:28:09 25 4
gpt4 key购买 nike

这个问题似乎经常被问到,但通过查看各种答案(非 Xamarin),它们都不适用于 Xamarin...

在我的 Activity 中,我尝试了多种形式:

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() Activity 中尝试过这个。似乎没有任何效果。

我读过: 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

Activity .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();
}
}
}

发现的问题:

我的搜索 fragment 中的这个编辑框导致键盘显示,打破了全屏模式,即使键盘消失,也不会返回全屏。

<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"/>

最佳答案

我建议对@Grace Feng 的回答做一点改进。如果我们在监听器的类中添加一个构造函数

public class OnGlobalLayoutListener : Java.Lang.Object, IOnGlobalLayoutListener
{

private int mScreenheight;

private View mDecorView;

public OnGlobalLayoutListener(int mioScreenheight, View mioDecorView)
{
mScreenheight = mioScreenheight;
mDecorView = mioDecorView;
}

public void OnGlobalLayout()
{
Rect r = new Rect();

var keypadHeight = mScreenheight - r.Bottom;
if (keypadHeight <= mScreenheight * 0.15)
{
var uiOptions =
SystemUiFlags.HideNavigation |
SystemUiFlags.LayoutFullscreen |
SystemUiFlags.Fullscreen |
SystemUiFlags.ImmersiveSticky;

mDecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
}

}
}

我们可以在任何 Activity 中使用它:

        RelativeLayout vista = FindViewById<RelativeLayout>(Resource.Id.main);

int altezza_schermo = vista.Height;

View decorView = Window.DecorView;

vista.ViewTreeObserver.AddOnGlobalLayoutListener(new OnGlobalLayoutListener(altezza_schermo, decorView));

关于android - 如何在 xamarin android 中隐藏导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42876362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com