0
我想在顯示軟鍵盤時保持狀態欄和工具欄在頂部可見。我嘗試了很多方法,但做不到。嘗試windowSoftInputMode和設置/清除窗口的標誌,但都失敗了。 任何人都可以幫助我嗎? Please click here to see gif file!鍵盤向上滾動並隱藏Android上的工具欄和狀態欄
我想在顯示軟鍵盤時保持狀態欄和工具欄在頂部可見。我嘗試了很多方法,但做不到。嘗試windowSoftInputMode和設置/清除窗口的標誌,但都失敗了。 任何人都可以幫助我嗎? Please click here to see gif file!鍵盤向上滾動並隱藏Android上的工具欄和狀態欄
這是一個Xamarin錯誤。見here。
有一些workaronds。你必須做到以下幾點在MainActivity:
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
//Remove the status bar underlay in API 21+
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window.DecorView.SystemUiVisibility = 0;
var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
statusBarHeightInfo.SetValue(this, 0);
Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
}
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
如果使用FormsApplicationActivity代替FormsAppCompatActivity,那麼你必須刪除下列行:
var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
statusBarHeightInfo.SetValue(this, 0);
你可以看到吉米·加里多here更多細節。
但隱藏動作條,如果您在MainActivity使用下面的代碼,所以只有上述方案的將無法正常工作:
Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
要解決該問題,什麼工作對我來說是刪除上面的這一行,並創建一個特定的主題,使ActionBar消失。
下的資源/價值/ Styles.xml我創建了一個新的主題(你可以改變你的,如果你已經有一個):
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarSize">0dp</item>
</style>
</resources>
而且不要忘記設置主題MainActivity,如:
[Activity(WindowSoftInputMode = SoftInput.AdjustPan, Label = "Test", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
我希望這可以幫助你。
請問您是否可以發佈您的佈局和活動代碼?並且爲windowSoftInputMode設置了什麼值? –