Custom title icon in activity - java

I need to dynamically set the icon in the title bar. Currently I have this code in my activity:
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.table_layout_activity);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon_procedure);
This works fine, except that it changes the font size and it removes the (default) border line at the bottom of the bar. I'd like to only set the icon and leave everything else as default.
Default title bar:
.
Custom icon:
.
Anyone can help?

Icon can be changed in multiple ways for Activities, programmatically for an individual activity as
In onCreate()
getActionBar().setIcon(R.drawable.icon);
// icon is image in res/drawable folder.
Or in actionbar theme, by adding this to your ActionBar style.
<item name="android:icon">#drawable/icon</item>
<!-- This changes icon universally for all Activities in application -->

Since you are using the action bar, use setIcon() on ActionBar to change the icon, and get rid of that other stuff.

Use setIcon() on actionBar() or change it directly in androidManifest.xml

Related

How can I hide the title bar in an android application

I have been trying to find a way to hide the title bar in my android application.
I used #android:style/Theme.NoTitleBar.Fullscreen in the android manifest. It worked but the background gets set to black and all the text views get set to white. Is their a way to have the background set to white and text to black without having to set them all individually?
For a simple version, try to use Theme.AppCompat.Light.NoActionBar. This will keep "light" theme but remove action bar.
You can ovveride the Theme.NoTitleBar.Fullscreen background color/text colors by applying additional styles. For example if you wanted your background color to be white you would apply the style:
#color/your_background__color

Preference Screen and nav & status bar translucent

I'm using System Bar Tint to make my status and navigation bars translucent and with the color i want. The github: https://github.com/jgilfelt/SystemBarTint
It's working perfectly! I hace one tiny problem, when the phone turns into landscape or portrait mode.
Because of the translucent status and nav, I have to get the layout and add a margin-top when im in portrait mode for example, simulating this way the space the status bar has.
But my problem comes in PreferenceScreen activity. I use:
addPreferencesFromResource(R.xml.preferences);
to create my preferences screen. And i cannot get the way to change the layoutParams.
Does anyone have a solution for this??
Thanks!
A1. Use Theme.
How to apply theme to PreferenceScreen elements of a PreferenceCategory
A2.
ListView listView = getListView();
and set layoutParams to listView.
PreferenceActivity is a subclass of ListActivity.

Customise Actionbar how can i achive?

i want to show two images in action bar without listing in menu.xml file
means i want to customise with image button or button and i want to set background color in action bar i want to try with onCreateActionView() this method can any one provide me deep knowledge ?
design a layout as per your need and use the code
actionBar.setCustomView(R.layout.test_action);
and u can use the buttons or images by finding its id from the action bar.

android change default color of selector and tab underline

How to change (using theme modifications) the default color of selector (ListView, GridView) and Tab selector/underline color.
I use actionbarsherlock and Theme.Sherlock as main application theme.
Below are the pictures describing what do I want to change.
Thanks
Unfortunately, if you want to style your action bar you will need to style its parts individually - there is no color attribute that would change the light blue color to something else.
Basically what you need to do is override styles and change some of the attributes and add some new drawables. If your action bar includes spinners, dropdown panels, radio buttons etc. you'll also need to provide new colored images for those. I recommend that you check the ActionBarSherlock styled sample (which you downloaded with the library), particularly its styles.xml.

Android: Spinner shows title bar for 1/2 sec

Currently I have set my app to be fullscreen in java rather than xml with:
// Full Screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.location);
This works fine except for one odd behavior with the spinners. When you select a spinner the title bar appears for a split second then returns to the background. Also the splash screen has this same code yet the title bar persists in that class as well. Any ideas why this is happening ?
In your android manifest add
android:theme="#android:style/Theme.NoTitleBar
I have this in each activity i've declared in one of my apps, but you can also apply it in the lay out.
manifest excerpt:
Layout excerpt:
using the layout method, child/nested layouts should inherit this unless its overridden, by theme or style. Hope it works.

Categories