question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot make the Actionbar transparent

See original GitHub issue

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

Yes

Tell us about the problem

Please, ensure your title is less than 63 characters long and starts with a capital letter. I am not able to achieve the transparent actionbar. I tried all the code shared here at github and on stackoverflow but it doesn’t work.

Which platform(s) does your issue occur on?

iOS/Android/Both

Please provide the following version numbers that your issue occurs with:

  • CLI: 3.1.3
  • Cross-platform modules: 3.1.1
  • Runtime(s): tns-ios = 3.1.0 │ nativescript │ 3.1.3
    │ tns-core-modules │ 3.1.1
    │ tns-android │ 3.1.1
    │ tns-ios │ 3.1.0

Please tell us how to recreate the issue in as much detail as possible.

Just create new project, and apply following code.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Yes. Check following:

ngOnInit() {  
        //ios back for titlebar - https://www.nativescript.org/blog/how-to-match-a-nativescript-actionbar-s-color-on-ios
        if (topmost().ios) {
            topmost().ios.controller.backgroundColor= UIColor.clearColor;
            var navigationBar = topmost().ios.controller.navigationBar;
            navigationBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);            
            navigationBar.translucent = false;
            navigationBar.shadowImage = UIImage.new();            
            navigationBar.backgroundColor = UIColor.colorWithRedGreenBlueAlpha(0.20,0.20, 0.20, 0);            
        }
    }  

simulator_screen_shot_sep_7_2017_6_05_03_pm

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
triniwizcommented, Sep 12, 2017

you can move the code lower in the lifecycle

ngAfterViewChecked() {
 navBar.barStyle = UIBarStyle.BlackTranslucent;
            navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
            navBar.shadowImage = UIImage.new();
            navBar.translucent = true;
}
2reactions
sserdyukcommented, Sep 7, 2017

@dotnetdreamer Here’s an example of working code. It’s a custom widget for NS Core, but you can adapt it for your needs.

import { ActionBar as BaseActionBar } from "ui/action-bar";

export class ActionBar extends BaseActionBar {
    private get navBar(): UINavigationBar {
        const page = this.page;
        // Page should be attached to frame to update the action bar.
        if (!page || !page.frame) {
            return undefined;
        }
        return (<UINavigationController>page.frame.ios.controller).navigationBar;
    }

    public update() {
        super.update();    
        let navBar = this.navBar;
        if (navBar) {
            navBar.barStyle = UIBarStyle.BlackTranslucent;
            navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
            navBar.shadowImage = UIImage.new();
            navBar.translucent = true;
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set actionbar transparent background - Stack Overflow
I have searched some articles about how to set the actionbar background transparent but it doesn't seem to work for me.
Read more >
No Action Bar & Transparent Status Bar - YouTube
Tutorial how to hide action bar and make transparent status bar in Android Studio.
Read more >
How to make action bar transparent in Android studio - Quora
Why to make Action Bar Transparent if u could just remove it. Remove it from style that you will find in the value...
Read more >
Make Action Bar Transparent - Jay Rambhia
I have been working on an app which produces long exposure effect. As of now, we are almost ready with the free version...
Read more >
Transparent Action Bar in custom themes? : r/Telegram - Reddit
After trying a bit, I just got it to work, just had to create a brand new theme based on Night Theme, not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found