my problem is simple, it is relative to only Lollipop 5.0
I have a main activity where I set a certain theme then I set programmatically a custom background to the actionbar:
context.getActionBar().setBackgroundDrawable(context.getResources().getDrawable(
getCustomColor(context, Theme)));
Then I open another activity, where I set my custom theme, and my custom background drawable, this time made traslucent:
mActionBarBackgroundDrawable.setAlpha(0);
context.getActionBar().setBackgroundDrawable(
mActionBarBackgroundDrawable);
When I press back, if finishes the activity correctly but then my main activity has the actionbar completely transparent!
It is as if changing the background of the actionbar in my 2nd activity, changes it also to the 1st one!
It works correctly from android 4.0 to 4.4.4
Can you help me?
Thanks and regards
What is your context here? If it is pointing to the Application, it might do so. Try directly using
getActionBar().setBackgroundDrawable(mActionBarBackgroundDrawable);
in your Activity or if you are calling from Fragment
getActivity()getActionBar().setBackgroundDrawable(mActionBarBackgroundDrawable);
Related
I am using DayNight theme in my application. And I have a button that changes the theme. In VK and Telegram app there is a beautiful reveal animation that changes the theme without restarting activity or something like that.
I have tried to make that with reveal animation implementation in different ways, but it doesn't work or working bad in some cases with AppCompatDelegate.setDefaultNightMode(...). All examples with that reveal animation are for ActivityA -> ActivityB, but I just need to update theme without starting any activity.
And one more thing: AppCompatDelegate.setDefaultNightMode recreates my activity, so do I need a custom theme changing implementation?
And main question: how to create that animation with theme changing?
Examples:
Telegram (From Dark to Light)
Telegram (From Light to Dark)
VK (From Light to Dark)
VK (From Dark to Light)
since telegram is an open source app you can find the code -> line 3154: github.
it seems that it converts layout into bitmap and use it with an existing imageView to animate circular reveal
I'm making an app that retrieve a lot of images from some server. I'm tinting each item in my List using Palette library. When a choose one I open another activity to show details of this item.
I want to build a theme based on the selected theme to apply in detail activity.
Is there a way to programmatically build a theme based on a Palette from a Bitmap?
If it is about the color of material design, there is a solution.
Remember: You cannot change the modify those colors at runtime but you can switch between themes at activity start.
When an user select a color, apply corresponding style and restart activity. Otherwise, change some other colors like Google keep
To set theme .
super.onCreate(savedInstanceState);
setTheme(...style.YourTheme);
To restart activity: Call the recreate() method of the activity.
I am trying to implement a splashcreen and I dont want to use a new activity for the splashscreen,
So I set visibility=gone on my listview, hide actionbar, leave the logo visibility=visible, sleep for a certain period and then show the actionbar again and set the listview visibility back to visible
This works, however there is a brief moment at the start when the actionbar is still visible before it gets hidden
Is there a way to fix this and have the actionbar be gone from the beginning?
I am using ActionBarSherlock and Galaxy S3 with 4.1 Jelly Bean.
Thanks
No. There is no way to do this without using two separate activities.
The action bar is initialized as part of the decor view which happens much earlier than your onCreate method. This means there will be the noticeable lag that you describe before it can be hidden. If you wanted to permanently hide it you could do so using a theme or window flag but once you do that there is no way to get it to appear.
Is it possible to use ActionBar without activity? I want to use it in the StatusBar view, instead of view highlighted with purple color.
This screen shot, based on an image from the Android ui pages, labels the different components, just to make sure we're talking about the same thing.
You can't add an ActionBar outside of an Activity. You need an Activity to get an ActionBar reference. ActionBar references are retrieved via the Activity API, by calling the getActionBar() method inside the Activity.
So you can't use an ActionBar to replace the StatusBar. You can change the StatusBar's color, and possibly layout, but only on a rooted phone. See this forum discussion for some perspective on the issue.
AFAIK, there is no API for changing the Notification Drawer's layout and functionality. There are no API methods that allows us to place an ActionBar inside the drawer outside of the notifications e.g. at the top of the drawer like in your screenshot.
You can create custom layouts for notifications(the messages inside the drawer). The Android Developer pages have an example on how to do it (see "Creating a Custom Notification Layout" at the bottom of the page). Again, you can't use an ActionBar but you can add Views to a Notification layout.
Use notifications. You will see something in the status bar and no Activity will be involved.
There's GOT to be a way to change the ActionBar from a class declared within an Activity:
(1) create method in activity to .setTitle
(2) pass activity context to Controller class (MVC) declared in Activity
(3) have Controller class call activity method to modify actionBar
...what do you think?
You should make a custom rom to change that view.
That Purple View is not part of your application but a part of Android.
If you do not want an Activity, why not make it transparent.
How do I create a transparent Activity on Android?
In my application, I want to make screen translucent at runtime on a click of a button.
I tried
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
in the onClick() method, but it did not work. Is there any way to achieve this?
The answer is to set theme before views are instantiated as #Selvin said. To do that, I restarted my activity on click of my button with some different theme.
You can set the activity theme to translucent in the manifest and in the main layout of the activity set a background, when you click the button just remove the layout background or set it to transparent.