The last few days I've been doing great stuff in development, but I've seem to have hit a wall on something probably stupid simple. It's annoying. I was hoping I could get some help.
What I'm trying to do
I'm trying to create the awesome transparent ActionBar animation effect from Google Music (as described by Cyril Mottier here)
The problem
I can't even get the actionbar to go into overlay / transparent mode.
My set-up
I've got a library-oriented set-up in Eclipse. I've got a library project (let's call it master) that contains all the actual code and activities. Then I've got a project, that just plugs into the master library (let's call it slave). Lastly there's some open source support libraries that master uses (among others is ActionBarSherlock).
The activity I'm trying to apply this effect to is in the master library. It is declared in slave's manifest as com.example.master.DetailActivity, and that works like a charm.
Also: The theme for the activity may come from several places. Either it's set by slave's manifest, or by master at runtime. Themes may come from the master OR the slave project.
What I've tried
Feels like everything. I've started out by creating a custom theme based on Cyril's article. I made sure that for every item I've had a version with and without the android: prefix as per Jake Wharton's instructions.
I've also tried setting it at runtime using requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
What I've got
Nothing. The theme applied succesfully (I can see the actionbar's colors change appropriately), but it NEVER goes into overlay mode, nor does it become transparent.
Help would be greatly appreciated, and would probably be helpful to other's trying this effect.
EDIT:
Here are my themes and styles. Codes are kinda messy because I've been experimenting with them to see where I was going wrong. AppTheme and Theme.TranslucentActionBar.ActionBar.Overlay both won't work.
/res/values/
styles.xml
themes.xml
/res/values-v11/
styles.xml
themes.xml
I'm testing on a Nexus 4 with 4.2.2 installed as well as a 2.3.3 emulator.
OK, so apparently, with my set-up, you can't do it using themes.
I ended it up doing it, globally like this.
setTheme(theme.whatever);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.color)); // This is #212121 solid color for the dark action bar.
The lines are spread out over my code, but this is the gist of it. The order is important.
I also found out that sliding menu seemed to be blocking the overlay mode. I had to remove the instance for it to work. I'm still looking for a way to enable both overlay mode and the sliding menu.
Related
I'm having a "this can't be right moment" trying to learn Android app development. I want to add some buttons to the top bar (app bar, toolbar, action bar, etc) of my Activity. Apparently this thing is called the app bar. But when I read the docs, I feel like I'm taking crazy pills:
This class describes how to use the v7 appcompat support library's Toolbar widget as an app bar.
Why do I have to use something called "appcompat" to add a toolbar? I don't care about backwards compatibility right now, I'm just coding an app to learn. Normally backwards compatibility shims/layers are an optional thing. I just want to do this in the most straightforward way at the moment - it'll be easier for me to learn that way.
There are other ways to implement an app bar—for example, some themes set up an ActionBar as an app bar by default—but using the appcompat Toolbar makes it easy to set up an app bar that works on the widest range of devices, and also gives you room to customize your app bar later on as your app develops.
Again, this sounds like the docs are saying that the method they advocate is not the simplest and most basic way, and that there's another. Then one of the very first steps in the tutorial is:
In the app manifest, set the element to use one of appcompat's NoActionBar themes. Using one of these themes prevents the app from using the native ActionBar class to provide the app bar.
Huh? So the first step to getting a toolbar is to turn off the toolbar? At this point I feel like I can hear clown horns going off. Am I being pranked? I don't think Google realize how bonkers this all sounds to a complete beginner.
Is there a way to add buttons/actions to the default Material UI ActionBar in an Activity, without going through the appcompat package?
At the moment, I'm stuck with a very annoying kind of "bug" I assume regarding all Pre-Lollipop Android versions. It appears that (support) fragments don't apply the activity's theme they're assigned to. To make my explanations a bit easier, have the following demonstration:
My app runs with a turquoise theme at first. Let's say, the user decided to change the turquoise theme to a red theme. He or she restarts the app and is greeted with the following:
(screenshot taken on an Android 4.4.2 tablet)
Terrible sight, isn't it? However, if I run the same app in an emulator with Android L the whole theme problem doesn't even seem to exist.
There's especially one thing which seems odd about the tablet screenshot. The fragment itself doesn't apply the theme but child components inside the fragment which get added lateron (like the view with the exclamation mark which is hosted by a ViewPager) take and apply the theme as if nothing happened.
I'm not quite sure what the issue might be. I've done everything as stated in every document available. I set the theme before I call setContentView(resource) in the corresponding activity. I tried to do the trick with ContextThemeWrapper but it was no use.
Relevant code:
The activity's onCreate()
The fragment's onCreateView()
The fragment's layout
Attributes
Themes (a lot of them)
I tried to resolve this issue for days now and I still can't find out why this is not working. I haven't found a suitable answer yet and would love some advise.
I've been the victim to my own stupidity. I had another close look on my project setup and found this:
My tablet takes its layout resources from the sw600dp-folder, but I forgot to change the corresponding layout to take attributes instead of hardcoded colors. I think I have to retire after making such a stupid mistake.
How Do I make deafult ICS style tabs in android 2.2. I don't want to use ActionBarSherlock, instead I need to apply custom drawables. Can someone help ?
I tried using 9.png but didn't help much, as it didn't fill the complete tab, instead it shows only some blurred extended background. If you are suggesting some drawables - Please provide the drawable as well.
You can download ready made demo from this link: ICSStyleTab. I tried it for one of the project and it is working fine. If you wanted to add pager functionality, you can easily add using FragmentPager from Support V4 Library.
Update: ICSStyle Tab With Pager Demo
Thanks.
HoloEverywhere is a library to provide ICS/Holo theme to pre-3.0 devices:
https://github.com/Prototik/HoloEverywhere
Even if you really want to write your own code, you can gain a great deal of insight simply by looking into its source.
I am currently trying to get the look of my app right. But I am having problems figuring out how to even set up a way to change themes. For one thing, is there even a way to change styles through code? I checked the method list and I saw nothing. This leads me to my actual question; is there a way that, like CSS, in which you style the parent, and then have it trickle down but also changed depending on the View? I looked at the Android docs, and they did not show any examples of this. Hopefully someone can give me an idea as to how to accomplish this, or if its not possible, to let me know that as well. Thanks in advance.
You should be able to do this using styles and themes. I've implemented this using Jake whartons Sherlock action bar. (I'm not certain if it's necessary) It involves using the comparability library which gives you the ability to use fragments and loaders as well. Look at his democode at http://actionbarsherlock.com/download.html. Look for where themes are mentioned and you will find the information you need. In the demo app you can change the theme in the top right corner and see how it affects the activities look and feel. It also shows many of the features available and the code to write them. I have found this an invaluable resource and it should show you how to theme your app.
There are lots of way to style ListViews to give them elegant look, but all of them involve modyfying the adapter or writing additional code.
With the release of Android 4.0, unfortunetely things have to change. Google polished their Holo theme and gave it new look. All of the developers are now encouraged to use it, in order to make all apps look the same.
And here's the problem. Google rolled out 4.0, but there are still people using older Android versions. We can't just leave our previous custom application themes and use Holo, because it will ruin visual experience for users with older devices. And we can't force 4.0 users just to use Holo, because let's be honest - it's still not perfect.
The goal is to use builtin themes system and prepare some alternatives for Holo, which will look great on all devices. Then we can just switch between Holo and our themes with just setTheme() and no additional problems. Unfortunetely it's not that simple. We are limited to the capabilities of existing theme system and some things are just hard to do. And here comes my question.
Taking everything I've mentioned into consideration, how can we control ListView look? I'm not able to figure out, how to:
create list with rounded corners and make sure the selector background doesn't ruin it when selecting first/last element
create rounded corners not for the list but sections separated by headers, something like here:
The solution should affect ListViews created by PreferenceActivity without any additional lines of code. Everything should be contained in the theme:
<theme name="SampleTheme" parent="android:Theme">
...
</theme>
I kindly ask not to post solutions that do not use styles & themes. They can be easily found in another questions, here on Stack Overflow.
Thanks in advance.
I can see two ways to solve this.
One is simply to use a theme for your listviews specifying the background, which in turn is a 9 patch with rounded corners or an xml shape you specify (with rounded corners as well). This will have the side-effect of the listview row selector appearing 'over' the background you specified, therefore kind of spoiling the effect. It is quite straightforward to implement though.
The second option is to simply always add headers and footers to your listviews, which have backgrounds that are selectors with rounded corners on top (and bottom). You can specify styles for these as well if you really want to.
Sorry for this last comment, but I had to say it. Please don't try to make your app look like an iPhone app :)