I was wondering if there was any way to feature a custom title with my own drawable -- and then subsequently put a progress bar in the title layout so that it acts like the built in android progress bar.
In my code -- I want to be able to call setProgressBarIndeterminateVisibility(true) and have that display the progress bar in my custom title bar.
Is this possible?
I have set up my application theme so that it uses a custom title -- but I don't how or where to put the progress bar in that layout.
Thanks in advance.
EDIT: Right now I use my own theme that looks something like this:
<style parent="android:Theme.Light.NoTitleBar" name="BaseTheme">
<item name="android:windowBackground">#drawable/splash_bg</item>
<item name="android:windowTitleStyle">#style/TitleBackground</item>
</style>
With the title background style as :
<style name="TitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">#drawable/title_bar</item>
</style>
To give everyone a better idea -- something like this.
Add this code in onCreate before any other code:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgress(xx); // Then use this to update the progress to xx amount
To turn on/off use
setProgressBarIndeterminateVisibility(false); //true to turn on.
I have used this in a login Activity, my problem is that I run most of the login async so I having problems updating the UI. But I do get the circular progress animation to display.
I have this working on a TabActivity being updated from an async call within an Activity Intent started by the TabActivity. I had to put the "requestWind...." lines in both the TabActivityand the called Activity. Also I have found using setProgress wasn't doing much, but the spinner animation was "spinning" the whole time so I'm happy.
Here is an great example of how to implement a custom title bar with a progress indicator:
http://downloadandroid.info/2010/08/creating-a-custom-titlebar/
My solution is to have an ActivityHelper class which extends Activity and includes this method as well as one to turn on or off the progress bar, then extend that class from each of my Activities.
I believe the only way to do it is to use your own custom title bar. You COULD override the android code since its open source -- but that might be a bad idea. The best thing to do is to make a title bar layout and just <include /> it in all the other layouts and maybe have a helper class to show and hide the progress bar.
In newer versions the technique of requestWindowFeature will not work. A better option would be to use the v7.widget.toolbar that google has provided. The following link gives proper detail on how to use it.
Setting up the Actionbar
http://developer.android.com/training/appbar/setting-up.html
Related
I am building an app that starts activities through intents. The design of my activities in XML shows an action bar but whenever I am debugging on a physical android device, every activity besides MainActivity loses the action bar.
The entire app bar disappears and the layout continues as if there isn't supposed to be one. What are some of the first places to look to fix this?
How it looks in Android Studio preview
How it looks on a physical device
check your theme you apply on activity or application.
if it has below code then it will not show you default action bar.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
try to remove this line to get default action bar or add action bar using <android.support.v7.widget.Toolbar
I might recommend using the Toolbar instead of ActionBar to ensure you are always getting a Toolbar on the desired activity. The Android Developer Docs do a great job at explaining how to add the Toolbar to any activity.
https://developer.android.com/training/appbar/index.html
I am using an Action bar in my project. I am displaying a progress bar via the below approach.
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
However, what I'd really like to do is replace the left most image icon with the progress indicator when arbitrary background processes run and then returns the usual icon when complete.
Can anyone tell me the steps needed to replace this icon with a functional Progress indicator. It only needs to be an intermediate one.
Looks like you can find some suggestions here: Android: dynamically change ActionBar icon?.
Specifically, you can access the icon by using
Activity.findViewById(android.R.id.home)
And then just set and re-set the icon as needed.
You need to build a custom layout for this and use actionbar.setCustomView(yourcustomlayout);
In your custom layout have an imageView(which is your app icon) and progress bar(initially which is set to invisible).
When running the background process just set the visibility between image view and progress bar.
I use setSupportProgressBarIndeterminateVisibility(true); in my activity to show a Indertiminate ProgressBar. This shows a large ProgressBar in the ActionBar. I want to use a small progress bar . How can i do this ?
Kind Regards,
You need to create a style in order to get a small progressbar.
See this link, where explains how to change the Default Indeterminate Progress Size in ActionBarSherlock
http://thanksmister.com/2012/03/30/change-default-progress-actionbarsherlock/
Now I have my nifty custom title bar in its own XML layout file and I've got my custom theme and style XML files. From my Activity class I can invoke it and it looks great.
Problem is my app has 14 Activities, each with their associated layout file. If I want to see the same title bar appear across my app, i.e., in all my Activities, the two main strategies I've seen are:
Put a an <include layout="#layout/my_title_bar" /> for my title bar in every layout file
...or...
Change all my Activity classes to derive from some common Activity that invokes the new title bar
Before I go off and do one of these I just want to make sure there's no more "centralized' way of doing it, like, say, in the manifest. There's no need to declare the default title bar in every activity, and it doesn't seem right to have to make separate changes for each activity for an app-wide feature like a custom title bar.
Thanks in advance for any tips!
I have an application which uses a custom title bar. However, when my application launches, I noticed that the default title bar is shown for a brief period of time. My problem is I don't want to show the default title bar while my application is loading. How do I hide the title bar while my application is loading so that there will be no hint of it and then show it afterwards?
So far, I tried the following solutions but none have worked:
Hide the title bar in XML and then set the custom title bar in code. (Problem encountered: I received an error message saying: "You cannot combine custom titles with other title features".)
In XML:
<item name="android:windowNoTitle">true</item>
In onCreate method:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//... some code goes here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_header);
Set the size of the title bar in XML to 0. Then change it's size via code later. (Problem encountered: I don't know how to set the size of title bar in code. Is it possible? I tried getWindow().setAttributes() and getWindow().setLayout() but both of them didn't worked.)"
In XML:
<item name="android:windowTitleSize">30dp</item>
Modify windowTitleBackgroundStyle and set a transparent drawable as background. (Problem encountered: The content of the title bar became invisible but a line below the title bar is still visible.)
In XML:
<!-- style used by windowTitleBackgroundStyle -->
<item name="android:background">#drawable/transparent</item>
Some explanations for what you've encountered, hopefully they help lead you in a direction you're happy with.
You've already seen that your theme is used to generate what you see during activity loading. What's happening is the system is generating a temporary/loading window based on your activity's theme as specified in your manifest while your process is still starting up. Your code may not even be running yet, and your own activity will have a different window. This is significant because a number of settings become locked in once the window's decor has been created, but you actually have two chances here. The window your activity uses hasn't been created yet when you see this loading state.
Setting no title in your theme isn't working because it maps to the window feature Window.FEATURE_NO_TITLE. This dominates over any other title window features you may request and once a feature is requested you can't un-request or remove it regardless of whether decor has been initialized yet.
As part of your theme, the title size is giving you predictable issues. Theme attributes can't be changed. However, which theme your activity is using can be changed before your window decor has been initialized. You can specify one theme in your manifest for the activity that will be used during loading and swap it out using setTheme on your activity. (Best place is probably in onCreate before setContentView, where you would otherwise request window features.)
Chances are the line below the title bar you're seeing is the android:windowContentOverlay - the drawable used to supply the drop shadow from the title bar over the content. On most devices the top edge of this shadow would probably appear as a line below the title bar area. You can set this to #null to get rid of the shadow entirely if you want.
What I've done is set the following in my 'application' tag in my manifest.
android:theme="#android:style/Theme.NoTitleBar"
And then, for each activity, I added
android:theme="#style/CustomTheme"
can you try to open application in full screen mode..then on load of application you can exit full screen.that way your title bar will not be visible while in full screen mode. This works in html.not sure if you can use this trick.