删除顶栏在Android上xamarin形式
我想包括一些解决方案:删除顶栏在Android上xamarin形式
<item name="android:actionBarSize">0dp</item>
或
var activity = (Activity)Forms.Context;
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
或
RequestWindowFeature(WindowFeatures.NoTitle);
或活动串
Theme = "@style/MainTheme.FullScreen"
但我找不到任何可行的解决方案,或者更确切地说,将歌词,电池时间等消除,但我仍然是顶级酒吧,我怎样才能完全删除它?
iOS上我已经添加:
UIApplication.SharedApplication.SetStatusBarHidden(true, true);
和作品......但是Android,他是让我该死:) 解决方案?
我用xamarin形式PCL
我styles.xaml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">#0084CA</item>-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#2196F3</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<!-- default -->
<item name="android:buttonStyle">@style/NoShadowButton</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#2196F3</item>
</style>
<style name="NoShadowButton" parent="android:style/Widget.Button">
<item name="android:stateListAnimator">@null</item>
</style>
</resources>
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
this.Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
var stBarHeight = typeof(FormsAppCompatActivity).GetField("statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (stBarHeight == null)
{
stBarHeight = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
}
stBarHeight?.SetValue(this, 0);
}
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
你应该绝对包含一些关于你的代码的描述。 – pijemcolu
我的回答是Xamarin论坛这个类似的问题:
这两个项目添加到您的主题为你定活动:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
https://forums.xamarin.com/discussion/comment/248555
编辑:为了使您更容易,改变你的风格,以本 -
<resources>
<style name="MainTheme.FullScreen" parent="MainTheme.Base">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">#0084CA</item>-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#2196F3</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<!-- default -->
<item name="android:buttonStyle">@style/NoShadowButton</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#2196F3</item>
</style>
<style name="NoShadowButton" parent="android:style/Widget.Button">
<item name="android:stateListAnimator">@null</item>
</style>
</resources>
不,不工作,是我的不幸的一天:) –
这是官方的方式来做到这一点。还有其他一些东西必须与我们的主题混为一谈。你可以在styles.xml中添加完整主题吗? – SuavePirate
也许我不添加官方主题?我如何检查是否添加主题? –
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window.AddFlags(WindowManagerFlags.TranslucentStatus);
return;
}
仅凭这一点不会将状态栏下方视图,而是摆脱的状态栏下方的黑色空间(高度为20px左右)。
您是否尝试将此项添加到您的活动中? '[Activity(Label =“@ string/app_name”,MainLauncher = true,Theme =“@android:style/Theme.Black.NoTitleBar.Fullscreen”)]' – Krumelur
是的,但不行,顶栏不隐藏 –