I am working with ActionBar and since I have Messaging functionality I wanted to notify user in ActionBar if he has any unread messages. It would look kinda like this:
However, I can't seem to find if this is supported. So, does anyone know if this is supported and how I would add an icon over existing ActionBar item in this fashion?
The best approach to this would be to create a modified drawable yourself and set it as the source of that particular ActionBar icon. To do this you can call invalidateOptionsMenu() and re-set the icon from within onCreateOptionsMenu(Menu). You can use a LayerDrawable to superimpose the number on top of your actual icon drawable.
I do not think it is something built-in in the API, however there is a simple implementation for a badge-button that might help you
Related
So I'm currently trying to migrate an app to use Material 3 consistently. Previously it was stiched together without any real design concept. Now I want to actually look like something to take serious.
One thing I haven't been able to figure out is how to give the status bar the same color as the title bar. Currently it looks like this:
The official documentation however lists the seamless version in the "What's new" section:
I'm currently using a LinearLayout with the Theme.Material3.DayNight theme (without any modifications for now) and from what I was able to learn from the documentation I need to make use of components like MaterialToolbar inside a AppBarLayout inside a CoordinatorLayout so everything works as intended. I tried doing that and the scrolling and lifting now works as described in the documentation, but the color of the status bar remains unchanged unfortunately.
I'm not sure at this point if my expectations are wrong or if my code is. I believe that there has to be a built-in mechanism that automatically adjusts the status bar's colour to dynamically match the one of the app bar. I might be wrong though and the material-components-android expects me to implement the logic myself. In any case, could someone point me towards an example implementation where this transition is seamless? This way I could modify my code to implement this behaviour.
I'm currently using com.google.android.material:material:1.5.0 in case this is relevant to the problem.
Thanks in advance!
I've run into a very peculiar problem with Toolbars. The way my team currently uses the Toolbar is via a wrapper class, let's call it WrapToolbar.
So WrapToolbar will internally setup a Toolbar, and exposes some common Toolbar functions. Things like setTitle, getTitle, etc are available.
This WrapToolbar also sets up a default icon. This way all usages of the WrapToolbar will have this icon available for the screens that need it.
The problem with this approach is that for screens that require additional icons, have to add them via a Menu XML and the onCreateOptionsMenu function.
When we do that, the default icon setup with WrapToolbar gets pushed to the left, and the new icons from the Menu XML get added at the end.
This has worked fine for us until recently when requirements changed, and now are asking for the default icon to be at the end all the time.
I'm currently wrestling with the idea of doing a custom wrapper around Toolbar that exposes the ability to add icons, get the title, set the title, etc. This way we can put the icons in any order, and have ultimate flexibility in how our Toolbar looks.
I'm looking for some guidance on what that might look like. I also want to get some feedback on whether my initial idea to solve for this is flawed in some way I haven't foreseen.
Menus have a built in ordering based on the android:menuCategory attribute - you can use android:menuCategory="secondary" to push a menu item (like your default icon) to the end of the list - all MenuItems without a menuCategory will appear to the left of it.
I am creating an android application and I want to customize the look and feel of the action bar of the application.
For my project I am using actionbar sherlock. Currently my app is looking like this:
I want to remove the logo of the application and also the application title from the action bar and replace it with the following image.
Is there any way to accomplish this. I have read that we have to use the style tag to do this. But since I am new I don't know where to write the style tag and how to implement this. Please help...
EDIT
The width of the new image should be adjustable i.e. my requirement is that its width should cover half of the action bar
All I want to achieve is something like this application which is available in play store.
Just use this line in your onCreate method:
Drawable d=getResources().getDrawable(R.drawable.action_bar_background);
getActionBar().setBackgroundDrawable(d);
That will change the background of your actionbar to whatever image you want.
Of course it is always important to have different sized images for different device sizes.
I hope it helps
Update your AndroidManifest.xml tag to include the :icon attribute.
See the developer docs for more information.
Example:
<application
android:logo="#drawable/my_logo"
....>
</application>
Another nice example, for use with a theme/style can be found here.
To hide the title text shown on the action bar see this post's accepted answer. You'll need to have a custom style applied to the action bar to hide the text. If you also want the icon to be larger than the allowed space, you'll need to also set the background of the action bar as explained by #Eenvincible.
It's also worth noting that you're breaking a lot of Android Design Guidelines. It'd be easier for you and better for your users to simply set the right icon/title and move on with the standard ActionBar look/feel. Worth a look: Android Design Patterns - ActionBar.
What you are seeing is actually the default icon. Replace ic_launcher.png file from the following folders(if it exists there) with your image.
/res/drawable
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-hdpi
/res/drawable-xdpi
/res/drawable-xxdpi
Also rename your image file to ic_launcher.png
To edit the text on right of icon, you can use:
getSupportActionBar().setTitle("ANY TEXT HERE");
As the title suggests I want to create a custom title bar for a PreferenceAcitvity.
I need to add a summary below the title. Currently it will only display a title, but I need a sub-title, just like any Preference can have a summary.
I have read loads of questions here, like this and this, but these all do something different; it's not possible to include a summary for the title with the first method. Creating a custom layout for every Preference also doesn't seem the wisest option, and is loads of meaningless work (I have tons of PreferenceActivity's. I am looking into extending something.
Also, I want to keep the default behaviour as much as possible, so I am looking into ways of adding a TextView to the default layout located in android-sdk-windows\platforms\android-16\data\res\layout\screen_title.xml
So I thought I would apply this layout to the method in the second Q, but now I run into the problem of resource id's used in the screen_title.xml file that aren't public.
I'm running out of ideas...anyone got some fresh ones?
EDIT:
I found a solution thanks to the accepted answer below.
To clarify a bit further: the method getSupportActionBar() in the answer isn't in the SDK, but comes from ActionBarSherlock.
This is a compatibility library to enable the ActionBar and FragmentActivity (amongst other things) on pre API 11 applications/ devices. It's quite a heavy library, around 11mb, so you will have to think about if it's worth adding 11mb to your application just to have a summary/ subtitle in your preference screen's. On the other hand, this ofcourse also allows you to implement the other features of the library, such as actually creating an action bar (and or menu).
If you are talking about Actionbar then you can do this:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setSubtitle("Test Subtitle");
I have a pretty simple question about the Android ActionBar... is this intended to be present in the app, to use as a sort of header, or is it only intended to show when the user hits the setting button on the device?
I'm trying to implement a menu that is always present in the app, like a logo for branding, and some other actions, like a search icon and perhaps a map icon to see the map functionality. Any suggestions? Also see this post here
The ActionBar is always displayed. Check out the Android Developer Site for more information on the ActionBar UI patterns and usage.
You can use the excellent ActionBarSherlock library to provide an ActionBar on 2.x devices.
The ActionBar sounds perfect for the branding/icons you want. You would use your logo as the icon, and then have Action Items for Search and Map functionality.
Have you put your android:targetSdkVersion to 11 or more ? ActionBar is available only for Honeycomb and ICS :)