I want to make the following image to be the background for the entire Xamarin.Android application:
I reference the image in Base application theme in styles.xml :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
.....
<item name="android:windowBackground">#drawable/ic_app_background_image</item>
.....
</style>
The background applies to all the application but the image has dark background:
Also the number 51 has some strange things around it.
When I set the android:background="#drawable/ic_app_background_image" to the most outer LinearLayout of an activity it works fine, it shows the screen like that:
How can I fix the android:windowBackground property setting the background to black issue so I don't have to put android:background="#drawable/ic_app_background_image" in the LinearLayout of every activity?
You can try following method:
1.Create new file name as bg.xml in drawable folder (bg.xml)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splash_background"/>
</item>
<item>
<bitmap
android:src="#drawable/splash_logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
2.define background color in colors.xml
<color name="window_background">#F5F5F5</color>
<color name="splash_background">#FFFFFF</color>
3.define new style MyTheme.Splash in style.xml and use the bg in item android:windowBackground
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
4.Usage in Activity
[Activity(Theme = "#style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
// other code
}
Update:
If you want to apply this style to all activities, you can just add the following code to your Base application theme. And we don't need to set for each activity. For example:
<!-- Base application theme. parent="Theme.AppCompat.Light.DarkActionBar" -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#drawable/bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
The result is:
For more details, you can check: https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
Related
I'm working on an application with Xamarin.Forms in Visual Studio 2019, I already have the splash screen but when I run it it doesn't cover the entire screen, it leaves a space where the notification bar should go, I already tried with the "NoTileBar" property and it did, but when opening it from the smartphone does not make the change. Could you help me change it?
Styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
enter image description here
styles.xml
<style name="MainTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
Check your MainActivity Flags as shown below
Add SplshActivity class
[Activity(Theme = "#style/MainTheme.Splash",
MainLauncher = true,
NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
// Launches the startup task
protected override void OnResume()
{
base.OnResume();
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
At first, if you want to hide the action bar in your activity, you need to change the <item name="android:windowActionBar">true</item> to <item name="android:windowActionBar">false</item>.
And then does the notification bar mean the system's status bar? If so you can try to use the following code to hide it:
WindowInsetsControllerCompat windowInsetsController =
ViewCompat.getWindowInsetsController(WindowDecorView);
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars());
For more infromation, you can check the official document about hiding the system bars.
enter image description hereHow to change the status bar icon color for splash screen (LaunchScreenTheme) in android ?
I tried the below code but it's not working .
<color name="ns_ThemeBase">#FFFFFF</color>
<style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="colorPrimaryDark">#color/ns_ThemeBase</item>
</style>
How to change the status bar background to white and the icons to black ?
If it helps, I wasn't able to make status bar transparent, my workaround is to hide it.
Try to add those two lines in your style :
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
You should have this (styles.xml) :
<!-- Launch Screen -->
<style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="colorPrimaryDark">#color/ns_ThemeBase</item>
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
</style>
Working example : https://github.com/mickaeleuranie/nativescript-stackoverflow-49236235
How it looks :
enter image description here
This is what i actually looked for and i achieved it by using the code
<style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimaryDark">#color/ns_ThemeBase</item>
</style>
Thanks for all your support , Cheers :)
I have 4 different activities on my app, in 2 of them it shows a white Title bar (with activity or package name) above my custom toolbar, but in other 2 this bar is hidden by the custom one.
I want to show only my custom toolbar and hide the default...
this is my "styles.xml" code:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryDarkColor</item>
<item name="android:colorAccent">#color/secondaryColor</item>
<item name ="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="MyActionBar" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:background">#color/primaryColor</item>
<item name="android:textColor">#color/primaryTextColor</item>
</style>
</resources>
[Solved]
I just change the class my Activities was inheriting from AppCompatActivity to FragmentActivity (until now I have no issues came from this change)
In my application default back button color is white. I need to change that back button color to black. I am tried so many post's for changing back button of navigation bar but no luck. Can you please suggest any idea. Here is my theme design.
style.axml:
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="Theme.Splash" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#drawable/Splash</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowBackground">#color/window_background</item>
</style>
</resources>
styles.xml:
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#fcce47</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#000000</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textCursorDrawable">#null</item>
<item name="android:datePickerDialogTheme">#style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>
I have write below code in styles.xml
you have to write below line inside mytheme.base
<item name="drawerArrowStyle">#DrawerArrowStyle</item>
you have to write below code in out side of the above style tag:
<style name = "DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/BackButtonColor</item>
</style>
I have an activity which is with the theme Theme.Transparent which is:
<style name="Theme.Transparent" parent="android:Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:gravity">top</item>
</style>
i'm trying to get rid of the border and the padding around it.. i want to make fill the horizontal of the screen. and no gray border.
please help :)
Be sure to create your Dialog referencing your custom theme:
Dialog dialog = new Dialog(this, R.style.MyDialogTheme);
Your custom theme needs to fill the screen and disable a couple of Android framework defaults:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyDialogTheme" parent="android:Theme.Dialog">
<!-- Fill the screen -->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<!-- Just to prove it's working -->
<item name="android:background">#ff0000</item>
</style>
</resources>
Same as above but doing it in code rather than in xml worked for me.
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Set width and height to match parent container.
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow()
.getAttributes();
wmlp.width = android.view.WindowManager.LayoutParams.MATCH_PARENT;
wmlp.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
The following works perfectly for me. It lets me have a full-width dialog (fills the screen's width with no padding) but with wrap_content for height, and it retains all my other stylings that I do in my builder:
<item name="windowMinWidthMajor">100%</item>
<item name="windowMinWidthMinor">100%</item>
<item name="android:windowBackground">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:background">#ffffff</item>
Background is required or else it does a weird repeat thing, but just set this to the color you want your dialog background to be. WindowBackground and WindowIsFloating are required to make the size wrap correctly.
Add your theme to your builder like so:
builder = new AlertDialog.Builder(_context, R.style.DialogTheme);
and you're good to go!