Programmatically setting the translucent theme at runtime - 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.

Related

Theme from Palette

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.

Android toolbar icons style

I'm working on an app which has two activites. The second activity has a back button which provide back navigation.
The problem I have is that the back navigation button takes the background from the toolbar no matter if the toolbar has the "style=" attribute or the "app:theme=".
Here is the toolbar with the "style=" attribute:
http://postimg.org/image/f57zaap4p/
http://postimg.org/image/3u5blxi9l/
An here is the toolbar with the "app:theme=" attribute:
htt.p://postimg.org/image/kkqxgo8d1/
htt.p://postimg.org/image/ofpq5i251/
(Please remove the point from "htt.p" from the last two links - I can't post more than two links)
I want the icons to have a white background. I would appreciate if you can help!
You can style the action overflow button in your styles.xml adding this line:
<item name="android:actionBarItemBackground">...</item>
You can set it as a #drawable or a #color resource. I suggest you to define a selector to manage, e.g, the background color as the icon is pressed.
As for the back arrow, this is, to me, quite an open question. You could take a look at my own question here , where you can also find a selector sample.
Basically you can override the arrow/burger background with
<item name="android:selectableItemBackground">...</item>
but (I fear) it acts as a background for a lot of widgets you might have. In facts, this also overrides actionBarItemBackground, so if you want to use both, the latter is enough.

Changing Actionbar Background programmatically in one activity, changes in whole application

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);

Change the down state color of the Android ActionBar UP/Home button

I'm using ABS, and I basically just want to know if there is any property that will let me overide the default blue I'm getting in a button down. My application is all red, and it's a small detail that's killin me. Ideas?
The actionBarItemBackground theme attribute will allow you to change the action item selector.
If you're using it with ActionBarSherlock be sure to provide an entry with and without the android: prefix.

Android - How to improve ListView performance when setting Theme.Translucent.NoTitleBar in Activity?

I have an activity with Theme.Translucent.NoTitleBar set as the activity's style attribute in the manifest.xml.
<activity android:theme="#android:style/Theme.Translucent.NoTitleBar"/>
I need that, because when launching the activity, I animate the rootlayout of this activity from the bottom to the top (like the ModalPresentation on iPhone) and I don't want to have a black background during this animation.
Everythings works, but the performance of the ListView I put in this rootlayout is very slow after applying the translucent theme.
I already tried setting BackgroundColors of the ListView and the rootlayout, but it seems, that android still considers the transparency while drawing.
Have you tried: getWindow().setFormat(PixelFormat.RGBA_4444); in onCreate()?

Categories

Resources