I have used XML to define the Theme of the action bar for my Main activity to be as follows:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light" />
<style name="HomeTheme"
parent="#style/AppTheme">
<item name="android:actionBarStyle">#style/HomeActionBarStyle</item>
</style>
<style name="HomeActionBarStyle"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome|showTitle</item>
</style>
Then in my Manifest file I have set the Theme of my activity with the defined Theme :
<activity
....
android:theme="#style/HomeTheme"
....
</activity>
everything went file as expected except two thing:
1) the border line of the action bar area is still blue
2) the background color of the action bar area is white not grey.
I am not sure what could be my mistake or this is just a bug in my emulator?
I need to solve the previous two points just to have beautiful GUI
Change
parent="#android:style/Widget.Holo.ActionBar"
to
parent="#android:style/Widget.Holo.Light.ActionBar.Solid"
By default the standard ActionBar has the blue line under it instead of the gray. The solid variant is probably what you're looking for.
Related
This is what my bottom navigation bar looks like at the moment:
Looks great right? Except that, right now you can see each icon clearly (or mostly clearly), however when you view it on my device you can barely make out the icons at all.
I have the following in my themes.xml at the moment:
...
<!-- Navigation bar colour. -->
<item name="android:navigationBarColor">#color/pink</item>
<item name="android:windowLightNavigationBar">false</item><!-- This does nothing -->
...
At the moment my minSdkVersion is 29 and my targetSdkVersion is 30.
How could I change the icons colour, or if that's not possible, at least have them a darker colour so they can be viewable?
You can't change color of navigation bar icons. But you can make it dark or light. Your pink navigation bar looks pretty light. So, set windowLightNavigationBar to true:
<item name="android:windowLightNavigationBar">true</item>
You could make it lighter only
Please try to this
<item name="android:navigationBarColor">#android:color/white</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
should be right. but you said it doens't work.
So I assumed there is another theme on your activity.
So, I sugest, in your activitiy or fragment code, how about set window flag directly.
try code below . It will make your icon dark
activity.window.decorView.systemUiVisibility = (
or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
You're in the themes.xml file- have you tried adding this to the styles.xml file?
<item name="android:navigationBarColor">#color/black</item>
Also, this Styles and Themes page might help you out! They have a comparison and pretty good explanations with examples. For example, you can customize the default theme that you're using like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I need a help about to find a theme who fits in this part of my project, but first I believe is nice to explain first the structure of the activities to find the answer:
Example of project style
The main activity (left) don't have any Action Bar, because takes to much space from screen an the Action Bar, polluted the design and is useless in this point.
The main activity, depending on the option of user, can go to 2 others activities, but both of them are kind of the same of the right activity(not eeeequal equal... is just to explain.) that consists in a Action Bar on top with the text of the result, a button back, one fixed part with some informations, and a Tab Layout with 3 tabs, each one, is a fragment.
the problem starts obviously, in this second activity...
I followed this site to build the screen at first: https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
but, with this site, they use this style:
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
But using this style, with what i need, the result is this error:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.TabLayout
So, to try to find the answer, i find this site over here: http://geeksmember.blogspot.com.br/2015/10/errorerror-inflating-class.html
Who shows me this solution on styles file:
<style name="AppTheme.Base" parent="android:Theme.Material">
Is a nice solution, is nice because in this moment i can separe the main style from the other style. Ok... buuuuut... when i start the aplication, comes this error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
so... that's my question... because, when i use the "Theme.AppCompat.Light.DarkActionBar" comes the first error again... and i stay on this situation who i can't find a style who doesn't match with my needs...
If anyone needs the style file... (this is the style file for all the activities except the main activity)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="***I Need a theme here, i know, this is my question*** :)">
<item name="android:colorPrimary">#212121</item>
<item name="android:colorPrimaryDark">#000000</item>
<item name="android:colorAccent">#303030</item>
</style>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#80CBC4</item>
</style>
</resources>
You have two choices:
Use a different theme for your two activities
To do this, you'd create an "action bar theme" and a "no action bar theme":
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#303030</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then, in your manifest, you'd assign the first theme to your app, and the second theme to any screen you didn't want an action bar for:
<application
...
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar">
...
</activity>
</application>
So this way, all screens will have an action bar by default, but any activity that should not have an action bar can be set up by specifying AppTheme.NoActionBar for that single activity.
Use a toolbar widget when you want an action bar
For this approach, you'd create your app theme to have no action bar:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#303030</item>
</style>
Then, in any activity that should have an action bar, you'd add a Toolbar to your activity's layout:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
In your activity's onCreate() method, after setting your content view, you'd tell the system to use this toolbar as the action bar:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Just started learning developing android in android studio, and created a custom theme which needs to hide the action bar on a inheriting styling.
On runtime the theme actually does hides the action bar but the preview does not, which makes it a bit difficult creating a layout based on the preview.
I've probably done something wrong or just not understanding how to use theme's and stylings with the preview correctly.
The custom theme I've made
<style name="AppTheme" parent="Theme.AppCompat">
...
</style>
<style name="AppTheme.MainLayout">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
The intention is to use the .MainLayout styling on certain activities instead of the whole application.
How I'am applying the usage in manifest file
<application
...
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/AppTheme.MainLayout">
...
</activity>
</application>
As explained this does hides the action bar on runtime but doe'snt in the preview.
I also tested how the preview does behave on applying the style directly in the layout.xml file.
activity_main.xml
<RelativeLayout
...
android:theme="#style/AppTheme.MainLayout"
</RelativeLayout>
For testing purpose I've added an extra styling in the AppTheme.MainLayout
<item name="android:textColor">#color/colorPrimary</item>
Result
What I am observing on this is:
The preview doesn't hides the action bar but does apply other styling (like the text color) correctly.
To wrap this question up: why is the preview different on not hiding the action bar when using the .MainLayout, and how to fix this?
Thanks in advance.
Edit:
Preview 'settings'
In your Design layout manager try to select Theme (click AppTheme).
Try to change:
<style name="AppTheme" parent="Theme.AppCompat">
to:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
I am working on an app which will be full-screen, but will utilize some of the functionalities of the ActionBar. With the Ice Cream Sandwhich release, I see that I get a blue line divider/separator as part of the ActionBar. Normally, it would be good for consistency, but in my case I need to remove the divider.
How can I remove or style the divider of the ActionBar in ICS?
Tried setting a custom theme with "android:style/Widget.Holo.ActionBar" as parent.
However, settings such as the one below has no effect
<item name="android:divider">#FFFFFF</item>
The graphic asset containing the blue bottom line is the background of the action bar's container view and is set to #android:drawable/ab_transparent_dark_holo when using the default Holo Dark theme.
To remove this line, you'll need to create a custom style for your action bar (based on Widget.Holo.ActionBar or Widget.Holo.Light.ActionBar (or the .Solid variants) and set the android:background to something that doesn't include the bottom border:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#drawable/your_background_here</item>
</style>
Note: Holo Dark/Light action bars have solid and transparent styles; this blue line appears by default for the transparent style. Holo Dark action bars are transparent by default and Holo Light action bars are solid by default.
Here is a simple way to remove the divider, works from API 07 using the actionbarcompat from the support library:
#Override
public void onCreate(Bundle savedInstanceState) {
//...
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.whatever_you_want));
//...
}
Changing the activity theme to Theme.Holo.Light.DarkActionBar removes the blue line.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:textColor">#android:color/white</item>
</style>
If you still want a black background you may want to change android:windowBackground and/or android:textColor
add this <item name="android:windowContentOverlay">#null</item> to your app theme.
In my application I am using my own theme based on the Theme.Holo.Light
However I have customised the actionBarStyle, setting the background drawable to a blue gradient to fit with my app's style.
However, with the Halo light theme, the action bar text is dark, & the default icons, such as the Up Nav arrow and the menu icon are dark, these don't go on my blue gradient.
As you can see from my XML below, I have managed to correct the title text colour but I can't find the attribute I need to override for the icons.
How can I change tell the theme to effectively use the icons on the ActionBar from Theme.Halo
instead of those Theme.Halo.Light but making the rest of my application remain using Theme.Halo.Light
Here's my current XML
<style name="MyLightTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/blue_gradient_light</item>
<item name="android:titleTextStyle">#style/Theme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/solid_white</item>
</style>
Thanks for your help
Use Theme.Holo.Light.DarkActionBar as your base if you want to do this. It will take care of these details.