PreferenceActivity action bar background color - android

Dears,
Look at the snapshot:
I use the following code to change the action bar background -same used in normal activities and works fine-:
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.actionbar_background));
actionBar.setIcon(R.drawable.ic_settings);
setupSimplePreferencesScreen();
}
the problem is that the action bar background color changed to specified color, but the text and icon background take the activity background color.
What's wrong?

This link help me to figure the problem:
My action bar title is taking the wrong color from theme
The problem was with setting Activity background color, instead of this:
<!-- Settings Activity -->
<style name="SettingsTheme">
<item name="android:Background">#color/main_menu_background</item>
<item name="android:textColor">#color/font_color</item>
</style>
I use this:
<!-- Settings Activity -->
<style name="SettingsTheme">
<item name="android:windowBackground">#color/main_menu_background</item>
<item name="android:textColor">#color/font_color</item>
</style>

Change:
actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.actionbar_background));
To:
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_background)));

Related

Action Bar black back arrow issue

Although I'm using dark action bar, back arrow color is black.
I declared theme as below in manifest :
android:theme="#style/Theme.AppCompat.Light.DarkActionBar
and screenshot :
Back arrow color should be white. How can I do this ?
One option is to set your own indicator
<style name="Example.Theme" parent="#android:style/Theme.Holo.Light" >
<item name="android:homeAsUpIndicator">#drawable/up_indicator</item>
</style>

App name(title) showing in a dialog

In my application i am using an activity as a dialog.Everything works fine but there is one small problem.Whenever the dialog is shown,the title bar is visible.I had done requestWindowFeature(Window.No.Title) but still the title bar is comming.
xml
<style name="CustomDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
you are using wrong theme
use this
android:Theme.DeviceDefault.Dialog.NoActionBar
also you can hide action bar programmatic .
for that you have to use this in your onCreate mathod
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.hide();
}
How about this ?
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.logindialog);
add this before you show the dialog
this answer originally form here

How can i remove icon and title from ActionBar in Android on startup?

In my android project, I wish to disable icon and the title in ActionBar.
Here is the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
But always on startup they appear and after a while they disappear but i don't want them at all. How can i remove them on startup?
call setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar.
actionBar.setDisplayUseLogoEnabled(false); should do it.
Or
For Splashscreen you should use this line in manifest and don't use getActionBar()
<item name="android:windowActionBar">false</item>
and once when Splash Activity is finished in the main Activity use below or nothing
<item name="android:windowActionBar">true</item>
Reffer this ----> click here
You can use below code for that -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar" />
If you want the full screen of your device you can use below code -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
And, also refer Developer's Site
Another method
Do this in your onCreate() method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
this refers to the Activity.
Maybe this answer can help you. It helped me.
<quote>
Best method is to set the display options to useLogo in your theme. E.g.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">useLogo</item>
</style>
This won't actually show the logo (if set) because showHome is not included.
</quote>
try this:
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
setContentView(R.layout.activity_main);
}
NOTE: The getActionBar() method was added in Honeycomb (API: 11) and later

Activity with action bar but without title?

How to achieve this? It seems very simple, but actually it's not easy to do it in acceptable way. I tried this:
1) in AndroidManifest I set activity theme to Theme.NoTitleBar. However, in my Activity then getActionBar() method returns null => UNUSABLE
2) I hide title programatically in my activity by calling:
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
and it helped, but there's a little delay, so I can see title bar maybe quarter of second after activity launch, then it disappears. It looks really lame.
Are there other options?
Apply a custom theme to your Activity, something like:
<style name="TestTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions"></item>
</style>
This will show the action bar with the logo, but no title.
Have u try bellow code :-
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.ur activityxml);
or also try below one
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activityxml);

Contextual Actionbar styles

I'm looking for style information on the Contextual Action bar (CAB). I just need to change the colour of the text in fact..
As you can see from the above, this is using the standard Theme.Holo.Light.DarkActionBar theme, so I just need to set the text colour to white!
Can anyone point me in the right direction?
To change the color/etc of the text in a contextual action bar:
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
//mode.setTitle("Contextual Action Bar"); (replace this call)
TextView tv= (TextView)getLayoutInflater().inflate(R.layout.contextual_title, null);
tv.setText("Contextual Action Bar");
mode.setCustomView(tv);
where layout/contextual_title.xml contains a single TextView with your desired color/size/style etc
In fact, almost everything in a contextual action bar can be styled. The only problem is that searching for the word 'contextual' leads nowhere useful. The relevant styling features are all called "actionMode...". Here are some I used (defined in my Theme.)
<item name="android:actionModeCloseDrawable">#drawable/check</item>
<item name="android:actionModeCutDrawable">#drawable/ic_menu_cut_holo_dark</item>
<item name="android:actionModeCopyDrawable">#drawable/ic_menu_copy_holo_dark</item>
<item name="android:actionModePasteDrawable">#drawable/ic_menu_paste_holo_dark</item>
<item name="android:actionModeSelectAllDrawable">#drawable/ic_menu_selectall_holo_dark</item>
<item name="android:actionModeBackground">#drawable/contextual</item>
<item name="android:actionModeCloseButtonStyle">#style/MyCloseButton</item>
<!-- these change the press backgrounds for the vanilla actionBar and for search -->
<item name="android:windowContentOverlay">#null</item>
<item name="android:selectableItemBackground">#drawable/bar_selector</item>
<item name="android:actionBarItemBackground">#drawable/bar_selector</item>
<!-- these were defined in platform/.../data/res/values/... but Eclipse didn't recognize them -->
<!--? item name="android:actionModeShareDrawable">#drawable/icon</item -->
<!--? item name="android:actionModeFindDrawable">#drawable/icon</item -->
<!--? item name="android:actionModeWebSearchDrawable">#drawable/icon</item -->
<!-- item name="android:actionModeBackground">#drawable/red</item -->
<!-- and finally -->
<style name="MyCloseButton" parent="android:style/Widget.ActionButton.CloseMode">
<item name="android:background">#drawable/bar_selector</item>
</style>
You can easily set your own text-editing cut/paste/copy/selectall icons, the bar
background, and the icon background that changes color when you press the icons(bar_selector above). The icons are ImageViews, not buttons, and the edit id's (and the pressable background) are attached to the ImageView's parent (one parent per view) which is an 'internal' type.
It's never clear what goes where in the styles--I found where selectableItemBackground was in the platform Themes.xml, and copied and modified the drawable pointed at.
I posted a comment to my own question, and this is actually a bug in the version of android I was using (Probably an early version of 4.0)
This is the bug described: http://code.google.com/p/android/issues/detail?id=26008
If you're starting the contextual action mode manually, you can call setTheme() with a new theme before launching it (maybe Theme.AppCompat.Light.DarkActionBar if you're trying to avoid the black-on-black text issue). This will not affect the theme of the current activity if you've already set the activity's content view.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity_layout);
// these lines can occur anywhere so long as you've already
// called "setContentView()" on the activity. The theme
// you set here will apply to the action mode, but not to
// the activity.
setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);
startSupportActionMode(myActionModeCallback);
}
it works now, but you have to enter it in values/styles.xml (not values-v#/styles.xml) and enter it in the general (non-API specific tag)
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionModeCloseDrawable">#drawable/ic_launcher</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

Categories

Resources