Removing the Android Title Bar - java

I'm developing an android application and I cannot remove the title bar permanently. A solution posted here: How to hide the title bar for an Activity in XML with existing custom theme
(the 600 upvoted one, the others didn't work as described below) worked in general, but it maintained the title bar for a brief millisecond when initially launching the app.
I've tried various solutions throughout stackoverflow and other sites modifying the android theme in the manifest xml and style file(s). However, all of these solutions have all crashed the application before it began. The message in LogCat being that I must use an AppCompact theme. My main activity extends the ActionBarActivity class, and I have tried switching it to just Activity while also removing the :
if (savedInstanceState == null) {getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
that is generated. However, when I do so, all of the views on the main activity disappear and it becomes completely white with nothing else. Is there a way to completely remove the actionbar while extending ActionBarActivity? If not, how can I switch to extending Activity or some other class while maintaining no other errors?

on styles.xml you should make that
parent="Theme.AppCompat.NoActionBar"

Do you use custom view for the ActionBar? if yes, then maybe you'll find the approach I use acceptable. I just set text color for Title and Subtitle the same as background color in my app's theme.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:titleTextStyle">#style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">#style/ActionBar.Subtitle</item>
<item name="android:background">#color/my_color</item>
<item name="android:backgroundStacked">#color/my_color</item>
<item name="android:backgroundSplit">#color/my_color</item>
</style>
<style name="ActionBar.Title">
<item name="android:textColor">#color/my_color</item>
</style>
<style name="ActionBar.Subtitle">
<item name="android:textColor">#color/my_color</item>
</style>
Then I inflate and apply custom ActionBar view in onCreate and set custom title

Related

Custom Alert Style with Multiple Theme

I am confused while using custom alert dialogue styles in my application, due to there being multiple themes in my application. I have three themes in my application, called themeGrey, themeTeal and themePink. I have an alert dialogue style like below
style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/colorAccent</item>
<item name="android:textColor">#color/colorAccent</item>
<item name="android:background">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="textColorAlertDialogListItem">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/colorAccent</item>
</style>
I have used it in my app like below
mProgress = new ProgressDialog((this), R.style.AlertDialogTheme);
Now my question is, how can I define a different style for each theme?
I do not want apply with a conditional. Can I do it by declaring a theme as an item?
Thanks
I have solved removing style from java code like below
mProgress = new ProgressDialog((this));
and delcared alert style in theme like below
<item name="android:alertDialogTheme">#style/AlertDialogThemeTeal</item>
Thanks

How to add custom style for cast button in cast sdk v3?

I integrated cast to my app, and the default cast button color is black, but i'd prefer it white.
So I have 2 questions :
From what style does it taken from default ?
How can i change the style or color of the icon ?
Im using cast sdk v3.
I read the other related posts but they're all relevant to sdk v2.
this is my menu item layout as in google sample :
<item
android:id="#+id/media_route_menu_item"
android:title="#string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
this is the menu code to create the button :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_podcast, menu);
mMediaRouteItem =
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
menu,
R.id.media_route_menu_item);
return true;
}
Solution was simple as changing the activity theme to extend Theme.AppCompat instead of Theme.AppCompat.Light.DarkActionBar
Try to check the Customize App guide for Castv3 in Android. You can customize the colors, the overlay style, controller style, and more.
Customize Theme
The IntroductoryOverlay class supports various style attributes that your app can override in a custom theme. This example shows how to override the text appearance of both the button and title over the overlay widget:
<style name="CustomCastIntroOverlay" parent="CastIntroOverlay">
<item name="castButtonTextAppearance">#style/TextAppearance.CustomCastIntroOverlay.Button</item>
<item name="castTitleTextAppearance">#style/TextAppearance.CustomCastIntroOverlay.Title</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Button" parent="android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Title" parent="android:style/TextAppearance.Large">
<item name="android:textColor">#FFFFFF</item>
</style>

How to change Android status bar color in all activities together

I learned how to color an Android activity status bar thanks to this solution: How to change status bar color to match app in Lollipop? [Android]
However it doesn't say how to make this for the entire app (all activities).
i don't want to duplicate those 4 lines of code into each Activity, and if I make a Java class for Utils, I can't reach my colors by using R.color.blue or getResources(....).
Is there a way to do this through the Manifest, perhaps? Or any other way?
Thank you!
You should create your own style in values/styles.xml. Then make your own theme with such parameters. Loock code below
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_secondary</item>
<item name="colorAccent">#color/color_accent</item>
<item name="android:statusBarColor">#color/color_primary</item><!--this is what you need-->
</style>
Or just use method (for Lolipop):
public abstract void setStatusBarColor (int color)

improve android tabs actionbar

I'm using this link for create custom tab in android. Now my problem is how to remove the dark horizontal line in center?
I want to have some thing like this:
In your styles.xml in your main app theme set the windowContentOverlay to null. Something like the code below.
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>

How can i change color of action bar and its over flow menu?

Here is a screenshot of my application:
I can access buttons using R.id.button1 and change its background using
case R.id.lightgreen:
for (Button currentButton : buttons) {
currentButton.setBackgroundResource(R.drawable.lightgreen);
}
Is there any way to access action bar and its overflow menu to set their color in same way?
[EDIT]
ActionBar actnbar;
actnbar.setBackgroundDrawable(R.drawable.blue_button);
this gives me error asking to convert blue_button to drawable but if i do that then i won't be able to set buttons.
Define your custom style.xml in values folder of your project like this :
<resources>
<style name="Theme.CustomTHeme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/Theme.CustomTHeme.ActionBar</item>
</style>
<style name="Theme.CustomTHeme.ActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/header_gradient</item>
<item name="titleTextStyle">#style/Theme.CustomTHeme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.CustomTHeme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
</style>
</resources>
And then in your AndroidManifest.xml :
<application
android:name=".App"
android:label="#string/app_name"
android:icon="#drawable/logo"
android:theme="#style/Theme.CustomTHeme">
...
You also must take care of supporting other api-s (other values folders).
If you are using actionbarcompat support library you can access actionbar in your activity that extends ActionBarActivity with getSupportActionBar() and use
setStackedBackgroundDrawable() or setBackgroundDrawable() or corresponding getActionBar() method if not using support library.
The Action Bar Style Generator is a great tool to style your action bar.

Categories

Resources