ProgressDialog Background Activity Fade Out Animation - java

I am building a custom ProgressDialog and would like for the background Activity to fade faster and darker than default. The only problem is I do not know where to look for the animation that handles the fading for a ProgressDialog. I have worked my way upstream from ProgressDialog -> AlertDialog -> Dialog but dont see anything in the java that looks useful. I am assuming there is an animation .xml file that controls it, so I am looking for that file, and how the calling program makes use of it.
Just to be a little more clear, the animation I am refering to is when a ProgressDialog pops up, the previously active activity fades to dark. I want to gain control of that animation.

The only ways I know of to alter the background dimming are via the android:backgroundDimEnabled and android:backgroundDimAmount settings (to completely turn on/off the background dimming and to control the amount of background dimming, respectively)
To alter these values, create (or edit) your res/values/styles.xml file with the following
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.ControlledDim" parent="android:Theme">
<item name="android:backgroundDimAmount">0.2</item>
</style>
</resources>
And apply that theme in the activity's manifest by setting the theme to
#style/Theme.ControlledDim
This may not offer as much control as you'd like but is hopefully a step in the right direction
(The default setting for android:backgroundDimAmount is 0.6)

Related

Animated background for button

How to make animated background for button in Android Studio
Hello guys, I am an java android application developer. In my project, I want to use a button with an animated background. What does it mean? The button class has a method .setBackgroundResource(int res_id), where do we pass R.drawable.some_res. I have video(R.raw.some_video). Can I use this video as a background for a button, and so that when it ends, it starts playing again. And another question is whether this background will consume a lot of phone resources.
To create an animated background for a button in Android Studio, you can use an animation drawable.
Create a new XML file in the res/drawable folder and give it a descriptive name, such as "button_background.xml".
In the XML file, add the following code:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/frame_1" android:duration="50"/>
<item android:drawable="#drawable/frame_2" android:duration="50"/>
<!-- Add additional frames as needed -->
</animation-list>
Replace "frame_1" and "frame_2" with the names of the drawables you want to use for each frame of the animation.
In your button's Java code, set the background of the button using the following code:
button.setBackgroundResource(R.drawable.button_background);
Note that the "android:oneshot" attribute is set to "false", which means that the animation will repeat indefinitely. If you want the animation to play only once, set this attribute to "true".
Keep in mind that using animations as background resources can consume more system resources than using static images, so be mindful of the size and length of the animation.

Strange issue with Android 6.0 and view backround colors

This happens only on Android 6.0 (Marshmallow). I have set my style.xml files to use the three colors:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#color/teal</item>
<item name="colorPrimaryDark">#color/oteal_dark</item>
<item name="colorAccent">#color/teal</item>
</style>
And in my Toolbar, a Tab View, and a single view... I reference the color using
android:background="?attr/colorPrimary"
However strangely when I open an activity with a view using that color... it's white (or most likely, set to transparent). When I return to the activity, the toolbar and tabview as well become transparent. Interestingly even if I hardcode the color into the view, it still happens. If I make the hardcoded value different (just by 1), the color shows up again.
It has something to do with the style, but I am not sure what. Has anyone run into this issue?
Ok, I found the issue. For a toolbar animation thing I was doing, I set the background to alpha 0.
mActivity.getToolbar().getBackground().setAlpha(0);
This background was being shared by other views. It seems in Android 6, the OS now shares the same object with various view so setting it to 0 here, will effect any other view in the app. My fix is to reset the alpha on fragment destruction.

How to set status bar tint color in layout/style XML?

I'm using the windowTranslucentStatus in my app theme.
Now, also want to tint the status bar to match my ActionBar.
Currently I'm using the SystemBarTint library, which is mostly fine except of one problem:
When the application launches, the OS shows a themed mockup layout as a splash image during the actual inflation. At that stage, there is no status bar tinting yet.
It looks like that (Took me 5 times to capture this screenshot during app launch):
Only after the activity is fully loaded the tint is applied. This is a problem for me and I'm looking for a way to somehow show the full branding on the status bar during launch.
I have read This blog post Which explains how you can actually control what will be displayed during launch by specifying a windowBackground.
I set the windowBackground to my main color -> then the entire screen painted pink.
I set background property on my activity's root element to white, but then again during launch the screen is pink, and only after the activity is loaded the content's background clears to white. This OK but not ideal.
I know I can create a bitmap with a white background and a color where the status bar should be, but then it won't be theme-able, meaning I'll have to create a new bitmap if the main color changes.
So to sum it up my question is this: Do you know a way to set a tint color for the status bar (in KitKat) in XML?
Alternatively, is it possible to create an XML drawable that will contain a colored bar at the top with a fixed height?
Here it is:
The (almost) perfect answer
Good to know that someone else was struggling the exact same problem like me.
To make it simple I'll post here the XML drawable:
window_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/status_bar_background"
android:drawable="#color/main_app_color"/>
<item android:id="#+id/content_window_background"
android:drawable="#color/white"
android:top="25dp"/>
</layer-list>
And now in my theme I assign this drawable as the windowBackground:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="BaseAppTheme">
<!-- Customize your theme here. -->
<item name="android:windowTranslucentNavigation">#bool/translucent_nav_bar</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowBackground">#drawable/window_background</item>
</style>
</resources>
As I have replied here, you can see a full working example I created here (unfortunately too long to copy, but rest assured that repo is going nowhere!).
Oh and from Lollipop onwards there won't be any need for tricks ;)

Why does my android emulator have different background than main.xml ?

So, I have a holo light theme, I am developing for android 3.0 and in my main.xml graphical layout shows a black screen which is what i want, but when I run the app on my android emulator version 3.0, it has a white background.
I want to have a black background, but main.xml layout shows me black background only the emulator shows different, why ????
Thanks, I have been developing for a week, but it's quite annoying. Thanks !!
The key is to customize Android Graphical XML Editor(Lets call it AGXE) properly to match the exact outcome of your program. For this purpose there are several ways of customizations are available.
In your case you are using Holo.Light the for your application, in your AGXE theme customization(in the light blue highlight) might be Holo/Theme.Holo (or something else) which has a black appearance for blank space.
If you want to know how your app layout will look in Holo.Light theme you have to manually set your theme to Holo.Light/Theme.Holo.Light
There are other controls in the AGXE, which can be used to get the most accurate representation of your layout in real life/emulator you specified (highlighted)(If you want explanations for each ask in comments below).
If you want to set a black background as Theme.Holo, you just have to put a single line code in all your layout android:background="#000000" which will set your entire background as black instead of white (even in Theme.Holo.Light), or you can specify your theme as Theme.Holo.
Read more here

ActionSherlockBar Styling - PopupMenu

Styling is a place for improvement in my knowledge of the android platform. Given I've being trying to make a simple change all morning and been unable to achieve it.
I want to change the style of the overflow menu in the action bar. I have been able to change the background color, and add animations, so that when clicked it fades to a selected colour. But for the life of me I cannot change the text colour.
Below are two screenshots, one using the Theme.Sherlock and the other using Theme.Sherlock.Light.
Theme.Sherlock - This is my current setting which I have customised. What I want is the overflow (aka android:popupmenu) to be in the holo theme (as below), and ideally so that I can change the text colour.
Theme.Sherlock.Light - This theme shows the style of overflow menu that I want to see. However, as highlighted in red, the overflow button is the wrong colour, and this theme also draws a horizontal line.
I don't know whether it is best/easier to change Theme.Sherlock with the popup issue, or Theme.Sherlock.Light with the overflow icon and line issue. The application is of a "Light" theme so option two is probably the long term better choice, however i'll accept an answer that can solve the problem by changing either theme.
p.s. Where do you find a list of attributes for changing theme/styles, auto-complete is very incomplete in eclipse.
Update
This is actually an update for native action bars as im back to the same problem, but no longer supporting 2.3 or below.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/OverFlow</item>
</style>
<style name="OverFlow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">**Insert your icon here**</item>
</style>
This answer is probably coming too late, but to those who may stumble across this question. I find it interesting that you were able to change the overflow's background color. I found that extremely difficult to figure out whereas changing the text was pretty straight forward. Just override the android:itemTextAppearance value in your custom theme.
<item name="android:itemTextAppearance">#style/your_new_text_appearance</item>
<style name="your_new_text_appearance">
<item name="android:textColor">#color/red</item>
</style>
I'm not familiar with ActionBarSherlock, but you can find the standard OverFlow icons on your harddisk in the folder
path\to\android\android-sdk\platforms\android-api-level\data\res\drawable-resolution
and they are called ic_menu_moreoverflow_normal_holo_dark.pngand ic_menu_moreoverflow_normal_holo_light.png
Alternatively you can find them online here.
I believe that the left circle is a drawable, too. Look inside the res\drawable.
Simple do the following:
1. In the theme.xml in your app theme style add this item:
<item name="popupMenuStyle">#style/PopupMenu</item>
2. In styles.xml add this new style:
<style name="PopupMenu" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:textSize">14sp</item>
</style>
In the style you may override text size or other parameters as you want.
Try to override style of Theme.Sherlock with help of Android Action Bar Style Generator

Categories

Resources