Status bar transparent on android with nativescript - android

I would like to know how can I set the status bar on transparent on Android with Nativescript ?
I read many post (How do I create a transparent Activity on Android?, https://blog.mindorks.com/how-to-create-a-transparent-activity-in-android...) but the status bar is always Grey or not transparence.
In values/styles.xml I added this :
<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
In AndroidManifest.xml
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="#style/Theme.AppCompat.Transparent.NoActionBar">
I'm confuse because it's like very easy. Maybe it's different on nativescript ?
I look this video https://www.youtube.com/watch?v=NroxMDGOJ_E but if I set this color "#00000000" or "#android:color/transparent" on ns_primaryDark it doesn't work.

Maybe this might be of some help then?
https://github.com/PeterStaev/NativeScript-Status-Bar
// Get reference to the Status Bar plugin module
import statusBar = require("nativescript-status-bar");
exports.loaded = function() {
statusBar.hide();
}

page.xml
page.js
page.css
Tested in Nativescript 6, Try this in your page's corresponding nativescript CSS file:
ActionBar {
opacity: 0;
}
0 here is complete transparency, where 0.5 is half transparent, and 1 is show the Actionbar completely.
A clean way to hide the actionbar is to just go to the javascript page, though:
exports.loaded = function (args) {
page = args.object;
page.actionBarHidden = true;
}
and in your XML page we add the loaded function that will receive the event, and the page, and hide that pages actionbar based on the attribute of "actionBarHidden":
<Page loaded="loaded">
<Page>

Related

How can I remove the status bar in android studio?

So basically I want to remove the status bar of my app and I've found no solution. I don't want to make my app fullscreen I just want that part to be transparent and have more space for my app. I tried changing the color of the status bar to transparent but nothing works. Any help would be appreciated! I will attach a photo with the part that I want to remove to be more specific.
https://i.stack.imgur.com/Zw5Tk.png
if you don't want to make your app full screen, you should make the status bar transparent. So add this line to your theme.xml file:
<item name="android:windowTranslucentStatus">true</item>
Therefore, your theme.xml should be something like this:
<resources>
<style name="Theme.MyApp" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
You can use WindowInsetsControllerCompat API to acheive this
You can try this function . Add this in onCreate() of activity.
private fun hideStatusBar() {
WindowCompat.getInsetsController(window,window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.statusBars())
}
}
Click here to read more

Ionic + Capacitor 3 + Android shows distorted splash image briefly

If you are using the #capacitor/splash-screen API to show a splash screen in your Ionic Android app with Capacitor 3 you might run into this issue:
Problem
For a fraction of a second the splash image will be shown distorted until it is shown in the correct aspect ratio. That means that it also "jumps" a bit on the screen This will especially be noticeable if you launch the app while the device is in landscape orientation or if you your device has stretched or fat display aspect ratio.
Background Info
It happens because AppTheme.NoActionBarLaunch that is used on app launch for MainActivity is set up to have the splash image as the background image, but the "real" splash image is initialized a couple of milliseconds later in the SplasScreen.buildViews() method of the plugin.
Solution
To fix it, you can change the following in your styles.xml file under /android/app/src/main/values:
Old:
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">#drawable/splash</item>
</style>
New (no background):
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">#null</item>
</style>
Or set the background color of your splash screen:
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">#ffffff</item>
</style>
This will prevent the showing of the splash image as a background image before the actual ImageView is added to the view hierarchy. The ImageView will have the correct scaleType as defined in androidScaleType of the plugin configuration.
Tested with the following versions:
#capacitor/android: 3.0.0-rc.0
#capacitor/splash-screen: 0.3.6
#ionic/angular: 5.6.3
The following configuration is used:
const config: CapacitorConfig = {
// ...
plugins: {
SplashScreen: {
launchShowDuration: 3000,
launchAutoHide: false,
backgroundColor: '#ffffffff',
androidSplashResourceName: 'splash',
androidScaleType: 'CENTER_CROP',
showSpinner: false,
splashFullScreen: false,
splashImmersive: false,
},
},
// ...
};
Note: No need to call SplashScreen.show() in the TypeScript (Ionic) code, it will automatically be shown. Just call SplashScreen.hide() in your TypeScript code once you want to hide the SplashScreen.
The above workaround does not work with the community barcode scanner which require transparent background.
My workaround (the drawback with blank white screen still exist there but it work):
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/white</item>
</style>
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar"></style>

Android: windowLightNavigationBar not working

Background: My background is in web development, ruby and javascript. I'm working on a mostly react-native app, so very likely I'm missing something basic.
What I want
android navigation bar to be white with dark system buttons see image in link white navigation bar
My Current Code
res/values/style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#FFFFFF</item>
</style>
</resources>
What is happening instead
The background AND the buttons are white. which is not so great for UX.
** What I have Tried **
this is what got me where I am now Change navigation bar icon color on Android
I have tried putting style.xml in a values-v27 folder.
I just worked on this same topic and found out you need to run at least Android 9.0 (or API level 28) on the device/emulator for this to work.
Also, I had to add this to the color of the bar:
<item name="android:navigationBarColor">#android:color/white</item>
So, recommended steps:
Create a values-v28 folder
Insert the style:
<item name="android:navigationBarColor">#android:color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
In your other values folder, you kind of have to live with the fact that this windowsLightNavigationBar doesn't apply...
Small remark
I also found a bug on this change, when putting app in background and then opening it again, the navbar buttons stay white for a second before getting the dark color
Your code is working as intended for me. Make sure you have the file name and file path written correctly:
https://imgur.com/xclYDuZ
A new approach would be:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.white)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars = true
}

Android - how to set theme values programmatically (from database values)

Is it possible if my theme values are downloadable from server then my mobile theme will change according to what I specify from it?
Example if I have columns [colorPrimary] and [colorAccent] from server then after downloading values, my app theme colors will change accordingly.
This is my current theme.
<style name="Base.Theme.Design" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#013034</item>
<item name="colorPrimaryDark">#013034</item>
<item name="colorAccent">#1490a0</item>
<item name="android:textColorHint">#9e9e9e</item>
</style>
Note: For all downvotes, please leave comment for improvement of this post. Thanks.
You can use Firebase remote config to apply that, for example if you have multiple theme options for your app like "Base.Theme.Design_A" and "Base.Theme.Design_B" which are already built-in your app. You can switch between and apply one of these themes by checking a remote property in Firebase remote config. Also you can change old value and fetch the remote values and activate them (not with style file)
<defaultsMap>
<entry>
<!-- color entries -->
<entry>
<key>colorPrimary</key>
<value>#013034</value>
</entry>
<entry>
<key>colorPrimaryDark</key>
<value>#013034</value>
</entry>
To change your app's colour dynamically, for elaborate implementations refer to this
There is a way to change your App's theme dynamically.
You need put two the themes in your styles.xml in advance, like this:
<style name="AppThemeA" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#aba424</item>
<item name="colorPrimaryDark">#9f2020</item>
<item name="colorAccent">#2a6c29</item>
</style>
<style name="AppThemeB" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#706464</item>
<item name="colorPrimaryDark">#831444</item>
<item name="colorAccent">#183150</item>
</style>
And use one of them in your codes.
For example, there is button in your MainActivity, if you click it, your theme will change to AppThemeA, so you need do this in your MainActivity's OnCreate:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if ("A".Equals(Intent.GetStringExtra("Theme")))
{
SetTheme(Resource.Style.AppThemeA);
}
else if("B".Equals(Intent.GetStringExtra("Theme"))) {
SetTheme(Resource.Style.AppThemeB);
}
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.bt);
button.Click += (sender, e) => {
Intent intent= new Intent(this, typeof(MainActivity));
intent.PutExtra("Theme","A");
StartActivity(intent);
Finish();
};
}

Remove pressed effect on action bar home icon

First, a few words about the app : minimum level is 16, I use a DrawerLayout (with the indicator) and have changed the background of my ActionBar.
When clicking on the home button to open the drawer, there is a blue pressed effect on both the image and the drawer indicator, that I'd like to remove. I tried setting selectableItemBackground in the styles to transparent, nearly everywhere I could think of, but that doesn't seem to change anything. Do anyone have a solution ?
Here is the image of this effect I'd like to remove :
Here is the styles.xml part for the ActionBar I'm using :
<style name="ActionBar.Solid.Bnp" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/action_bar_green</item>
<item name="android:titleTextStyle">#style/ActionBar.Title</item>
<item name="android:actionBarItemBackground">#null</item>
</style>
and finally the drawable used for background.
selectableItemBackground is close, but you need to use the actionBarItemBackground attribute instead.
For instance:
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#null</item>
</style>
You should keep in mind that the system uses this attribute in the ActivityChooserView too, which is what the ShareActionProvider returns in ActionProvider.onCreateActionView.
To highlight all this, here are the results when you use #android:color/holo_red_light instead:

Categories

Resources