In the xml graphical layout of my android application there is a actionbar shown in one of my android studio projects and not in others. Out of curiosity i would like to know the reason behind this. I don't see any changes in the themes of either of the layouts and activities.
Something like this is shown :
PS: the part above the dotted line is the actionbar. I want it removed somehow. It's not there in any of my other Android Studio projects.
Try adding this in your styles.xml
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and add AppTheme.NoAction to your activity in Manifest
Related
I want to know if it is possible to disable night/dark mode into android studio´s apps because, in my case, it breaks my app´s aesthetic.
I´ve tried using this code line into all my activities but it didn´t work:
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
If there aren´t any way to disable night/dark mode, can you tell me what do i have to do in order to make my app respond properly to color changes due to night/dark mode? (This includes background colors, drawable´s shapes colors and every color that gets modified by this mode)
(I accept documentation or any kind of information that can helps me solving this BIG problem)
My styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:padding">7dp</item>
</style>
</resources>
Finally solved the problem disabling dark/night mode. We have to add the following code into our AppThemes:
<item name="android:forceDarkAllowed">false</item>
I have three activities on my App. MainActivity's layout is a DrawerLayout with fitsSystemWindows="true". The other two activities' root element is a CoordinatorLayout with the same properties. I've defined android:launchMode="singleTop" for all activities in the manifest.
All activities use the same theme AppTheme, which has the following attributes:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:navigationBarColor">#color/colorPrimaryDark</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowBackground">#color/background</item>
<item name="android:colorBackground">#color/background</item>
</style>
This works for the MainActivity, but does not for the other two, where the statusbar is black (instead of transparent as it should be). This was not the case with the previous version (v7:27.0.2) of the support library. Anyone have any idea what might be wrong here? Thanks in advance!
I have the same problem, with a slight twist: my status bar is completely white rather than black.
I had "solved" this problem by sticking with support-v27.0.2 when I first tried to upgraded to support-v27.1.0. However, support-v27.1.1 is now released and the problem persists, so this is not likely to be a bug by google, and therefore needs a proper fix.
The solution that works for me is exactly as described by Thomas Vos in the comments below the OP. I thought it would be worth giving further detail here, as this appears to be the best solution.
In "styles.xml (v21)" you will likely have a style called "AppTheme.NoActionBar" which will look something like this:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
You obviously may have additional items if you have edited the style, but whatever you have, just add the following to the bottom of the list between the style tags.
The status bar should then be back to normal.
<item name="statusBarBackground">?attr/colorPrimaryDark</item>
I "solved" this by downgrading to support-v27.0.2. This is unfortunately one of those (not-so-rare) cases where Google changes something and doesn't document it anywhere.
I am studing Support Design liabrary.I cannot understand the use of enterAlwaysCollapsed.It seems it will influece on pull down,but I tried and find nothing changed.
So,what is the use of enterAlwaysCollapsed,could you show me with a demo?
Let me answer it myself.
First the activity theme is AppTheme.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
And then Don't set fitsSystemWindows in xml.
Last use scroll flag scroll|enterAlways|enterAlwaysCollapsed.
The final effect is below
I'm using a theme that inherits from "android:Theme.Material.Light" and am unable to find a way to hide the action bar from the xml style customizations. When using "Theme.AppCompat.Light" I was able to do it with something like this
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
How can I achieve a similar result with the material theme? I know you can hide it programmatically but not only is it inconvenient because you can't actually see the real layout on Android studio without having to run the app every time, but also, the action bar still appears for a second when you run the app, before getActionBar().hide() is run and it looks really unprofessional.
SOLUTION:
<style name="MyTheme" parent="android:Theme.Material.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="MyTheme" parent="android:Theme.Material.Light.NoActionBar">
<style name="NoActionBar" parent="_AppTheme">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowNoTitle">true</item>
</style>
and then apply the style to the Activity in your manifest as follow :
<activity
android:name=".youractivity"
android:theme="#style/NoActionBar" >
then if your java class extends the ActionBarActvity fix it to extend the Activity and also you had to change all the other Acivity to extend the Activity Class not the ActionBarActivity :)
i hope this will help you :)
Well I'm a bit late, but if someone is interested here is my solution.
I needed to inherit from a theme which has the action bar visible, so not using theme.NoActionBar.
Looking into the system theme here's what I found:
<style name="MainTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I am trying to find a way to write less and more easy-to-understand styles for Android. Sometimes I am struggling to debug and I am loosing many hours just to find out why one of the actionbar's view does not have the correct text color (this was an example).
I think you know what I'm trying to say... you have the two XML files opened (one in left, the other on the right side of your IDE) and you are trying to identify each XML tag and you are applying different layout attributes to support backward compatibility for older versions of Android.
Let's take an example: customizing the actionbar.
Our manifest file:
<application
name="com.app.App"
theme="#style/AppTheme.NoActionBar" > ...
Currently, you need to create two (or more) XML files to apply the following attributes to your actionbar:
API <= 10
res/values/themes.xml
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
</style>
API > 10
res/values-v11/themes.xml
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
This way we removed the actionbar from the activity. However, this is not complete, because on API <= 10, the screen isn't in full screen as on API > 10. You will see the app's label in the top of your activity. So, to have the same design on the two different devices, you need to add more code to your activity:
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
This was a small example, but this is way more complicated when you have many, many more styles declared in your files. At some point you will get lost.
What I'm trying to do is to simplify the work.
Can I merge the XML files without compile error and without duplicating the XML files?
res/values-v11/themes.xml
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
</style>
The above code won't work on API <= 10, but the code below does:
res/values/themes.xml
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
</style>
The above code is working, but some attributes is requiring the Android's namespace: android:tag. Otherwise, your IDE won't compile your project.
So, to suppress the errors, we can use xmlns:tools, which will remove the lint errors, and you can compile your code. However, you may also need to apply the tools:targetApi="lvl" attribute too:
res/values/themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar" tools:targetApi="11">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
</style>
</resources>
This way it's much more easier to maintain your code, and you will write less code than creating N xml files. However, sometimes, things are getting much more complicated, when you have more than 500+ lines in your XML file. The worst part is, the IDE won't show you any warnings or errors, the project can be compiled, but on different Android versions the layout will be different.
Finally... is there any way to write less and much more maintainability code?
You can do this:
res/values/styles.xml
<resources>
<styles>
<style name="AppTheme.ActionBar.Common" parent="#style/Theme.AppCompat.Light">
<!-- Common items -->
</style>
<style name="AppTheme.ActionBar" parent="#style/AppTheme.ActionBar.Common">
</style>
</styles>
</resources>
res/values-21/styles.xml
<resources>
<styles>
<style name="AppTheme.ActionBar" parent="#style/AppTheme.ActionBar.Common">
<!-- Specified items for v21 -->
</style>
</styles>
</resources>
Then, you use the AppTheme.ActionBar where you like and it will work in all versions:
<application
name="com.app.App"
theme="#style/AppTheme.ActionBar" > ...