How do I get rid of the empty space shown below (the space between the horizontal red lines)? I didn't see this on my app until getting a new phone (Samsung S8), which has more vertical screen space than my old HTC One.
The beginning of the layout file for that activity is:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout ...
My values-v14/styles.xml is
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
I tried googling this problem but I couldn't find anything -- I must be searching for the wrong terms. What file do I need to edit to make the empty space above my app's action bar go away?
Edit: for comparison, here's what the app looks like in the emulator (it looks the same way on my HTC One):
I'd like the app to behave the same way as above (i.e. no black space above the action bar) when I run it on my Samsung S8. What do I need to change?
change this <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
hopefully this will help you out , if not Kindly post your full xml file
happy to help
This is happening due to the wider aspect ratio of the Samsung Galaxy S8. By default, Android applications support a maximum aspect ratio of 16:9. To solve, add this element inside the <application> tag in your manifest:
<meta-data android:name="android.max_aspect" android:value="2.1" />
Full details available in this Google blog post: https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html
Related
Please notice that there is a mid-GREY banner above the app. How can I
Remove this (the app should ideally begin right below 9:56)
Change the background color (less ideal)
TLDR;
It's a display bug on the Pixel 4 emulator. Real Pixel 4 doesn't have that gap.
Edit
My answer below was not spot on. I tried on an emulated Pixel 4, API 29 (with Android Studio 4.2, macOS Big Sur) with rounded corners, as yours, and it rather seems to be an issue with the curve of the phone than an empty ActionBar.
My app on a pixel 4:
Even Youtube has this space:
Edit 2
Compared with a real Pixel 4
We clearly see that this gigantic gap is only on the emulator.
That's a bug on the emulator, and probably the main reason why no one talks about it around the web (googling Pixel 4 status bar height shows angry Pixel 5 owners results about its huge height).
Didn't found any bug report about it, I'll file one.
Old answer
What you see is probably an empty ActionBar, that has the same color of your StatusBar.
If you use the default theme, your app will use it :
Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar.
It displays your Application's name, defined in your MainApplication's android:label on your AndroidManifest.xml (or MainActivity's if not found). As it's empty, there's just an empty space displayed.
As you manage your own navbar, you can disable with the base theme of your choice Theme.AppCompat.*.NoActionBar, on values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- You can set the color of your status bar here, or with RN - see further on the answer -->
<item name="android:statusBarColor">#color/dark</item>
</style>
Don't forget to apply this theme to your MainApplication, in your AndroidManifest.xml:
<application
android:name=".MainApplication"
android:theme="#style/AppTheme"
...
To illustrate better, here's what it looks like:
With the NoActionBar (code above)
With parent="Theme.AppCompat.Light" and <item name="android:statusBarColor">#color/dark</item>
With parent="Theme.AppCompat", and an empty app name.
For the second part of your question, you can either change the color of your status bar here (see the docs for this), or within React Native.
go to
android/app/src/main/res/values/styles.xmlandroid/app/src/main/res/values/styles.xml
and add this code. it will remove
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">
#000000
</item>
</style>
</resources>
I am making a dialog, where I want to show EditTexts and Radio buttons.
But the theme is not applying. According to Layout Inspector, the Views have the correct theme applied (shown "forced"), but there is "android:style/Theme.DeviceDefault()", which is also "forced" (it is shown above my style, if that matters).
The problem is, that the Views look differently on different APIs, which I guess is caused by that DeviceDefault. I have not set anywhere anything about DeviceDefault, but it applies to all my Dialogs.
Any idea how to dissmiss it? Thanks.
Every API level has its own default theme and since you use the default theme to your app, android adjusts the theme depending on the API level which will be different on each device. Just remember that just the element of which you add the style attribute to gets the specified style attributes. The child objects or child view does not get the style attribute. If you want child views to inherit styles, instead apply the style with the android:theme attribute.
The problem is probolby linked to where, and how, you apply your own theme.
You should apply your theme in the AndroidManifest.xml file. If you apply your theme in the application tag or the activity tag, you cover different parts of the application with your theme. What you have done is hard to say without any code present.
You should apply your theme to one of the following sections of the file.
To cover the whole application
<manifest ... >
<application android:theme="#style/Theme.AppCompat" ... >
</application>
</manifest>
To cover just one activity
<manifest ... >
<application ... >
<activity android:theme="#style/Theme.AppCompat.Light" ... >
</activity>
</application>
</manifest>
If a view supports only some of the attributes that you declared in the style that you created, it then only applies those attributes and ignores the ones it does not support.
If you want to change the default style and colors, you can override them in the styles.xml file. Search for the item name that represents the color value and change corresponding value in the res/values/colors.xml file.
I hope this information will solv your problem, but as I said, it this really hard so exactly say without the code present.
About Theme.DeviceDefaul in Android:
There are many Themes available for Android devices.
Theme: the default for the earliest versions of Android up to 2.3 Gingerbread(10)
Theme.Holo: from Android 3.0 Honeycomb (11)
Theme.Material: from Android 5.0 Lollipop (21)
Theme.DeviceDefault: from Android 4.0 Ice Cream Sandwich (14), a theme that can be customized by the device manufacturer. It represents the native look of the device.
Specifying different themes:
Android's resource overlay system allows to specify styles based on device API level, via Android Studio will setup for you.
For example different versions of a style in res/values-v11 and res/values-v21.
/res/values/styles.xml is applied to every device and serves as base:
<resources>
<style name="AppTheme" parent="android:Theme.Light"/>
</resources>
/res/values-v11/styles.xml is loaded on all devices that have API level 11 and above (including those that are 21 and above):
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light"/>
</resources>
/res/values-v21/styles.xml is loaded on all devices that have API level 21 and above:
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light"/>
</resources>
AndroidManifest.xml is the place where the custom theme is put to use.
<application
android:theme="#style/AppTheme"
...
Recently I have read a chapter about dialogs in The Big Nerd Ranch Guide (2nd edition) and I have done everything by the book. However there are some issues, which are not mensioned in the book. Preview area of Intellij Idea doesn't work correctly with AppCompat themes.
This is my current theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
And this is what I have in preview area:
In the Internet I have read that using Base.Theme.AppCompat.Light.DarkActionBar may help. It removes the message, but ActionBar dissapeares also.
Oh, and DatePicker doesn't work with both and any Material Design:
This is just a render issue, because both themes work fine on devices. Can someone try to preview DatePicker in IDEA and Android Studio with AppCompat theme? May be this is just an IDEA issue.
P.S. dialog_date.xml
<?xml version="1.0" encoding="utf-8"?>
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog_date_date_picker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:calendarViewShown="false"
/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.criminalintent" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".CrimeListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CrimePagerActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
Whole project: https://onedrive.live.com/redir?resid=4653F2D263EA4131!21585&authkey=!AESze90_ZZ0p9WY&ithint=folder%2cproperties
Switching Themes
If you look at the declaration for Theme.AppCompat.Light.DarkActionBar, it aliases directly to Base.Theme.AppCompat.Light.DarkActionBar in AppCompat's values/themes.xml file:
<!-- Platform-independent theme providing an action bar in a dark-themed activity. -->
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" />
source
This isn't aliased in any of the other device configurations (e.g. values-v23/themes.xml, values-v18/themes.xml, etc). Have a look at the resouces for AppCompat here. This means that for every device, Theme.AppCompat.Light.DarkActionBar will always and only alias to Base.Theme.AppCompat.Light.DarkActionBar.
The docs for the Base theme make this even more clear:
Themes in the "Base.Theme" family vary based on the current
platform version to provide the correct basis on each device. You
probably don't want to use them directly in your apps.
Themes in the "Theme.AppCompat" family are meant to be extended or
used directly by apps.
source
So your switching from Theme.AppCompat.Light.DarkActionBar to Base.Theme.Light.DarkActionBar will never affect how things are displayed on actual devices and really isn't a change. The fact that Android Studio behaved differently is a problem with Android Studio (which I was unable to reproduce using your code on AS 2.0 preview 9).
Problem with Android Studio
I'll say that the Design tab has always been a bit flaky. It's getting better but hasn't always played nice, especially with support library stuff. To change your app's theme (even if what I said above wasn't true) just to make the Design tab look pretty is probably a bad idea. Think about your users. If you really want to know what your screen looks like, then deploy it to a real device or emulator.
Dialogs
I was also unable to reproduce your Dialog problem in AS 1.4 (stable) or AS 2.0 preview 9 (canary, ATM). But since your entire layout file is a DatePicker, I don't think you will get much benefit. This is even less beneficial when you consider that your DatePicker will be displayed in a dialog (which the Design tab is unable to simulate). I don't mean to sound harsh but you might just have to bite the bullet and use an emulator or physical device.
Make your style.xml look like this, toolbar will show up:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And your DatePicker needs to loo like this:
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:datePickerMode="spinner"
android:id="#+id/datePicker" />
If you need CalendarView in your xml add this insted of DatePicker:
<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/calendarView1" />
Shitty Android Studio 1.5.0 should be updated to 1.5.1. So easy
The "Rendering problem" states Couldn't resolve resource #style/Widget.Holo.Actionmode but when I do a project/path search for Widget.Holo.Actionmode it isn't there.
As a result, my soft numeric keypad won't display.
What the heck do I do? I've changed the styles in the Android Studio 1.1.0 dropdown in design mode but no matter what I choose I get the rendering problem and no keypad. I had colors set to Holo this and that because I liked the shades and I had Holo as the theme from the dropdown. I also have in AndroidManifest.xml this:
android:theme ="#style/AppTheme"
But when it was working, I had commented that out to get nice black background. Either way, no keypad.
All I have in styles.xml is this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.ThemeOverlay.AppCompat">
<!-- Customize your theme here. -->
</style>
</resources>
I exited and re-entered AS. No keypad; same problem.
I'll post all xml and activity java code if need be. This is insane.
Looks to me like there's a problem in APIs 17 & 18 with the definition of Widget.Holo.ActionMode. I added the following to my styles.xml file:
<!-- Put this here to fix rendering error in API 17-18 -->
<style name="Widget.Holo.ActionMode" parent="#android:style/Widget.Holo.ActionMode">
<item name="titleTextStyle">#android:style/TextAppearance.Holo.Widget.ActionMode.Title</item>
<item name="subtitleTextStyle">#android:style/TextAppearance.Holo.Widget.ActionMode.Subtitle</item>
</style>
This may happen on APIs below 17, haven't tested. It was fixed in 19.
my problem is an Android app, that uses android:Theme as a default style and android:Theme.Holo.Light for OSes of version 11 and newer and android:Theme.Holo.Light.DarkActionBar for v14 and newer.
The app project was created using the ADT Eclipse-wizzard, so the AndroidManifest.xml sets android:theme="#style/AppTheme", and there are three styles.xml files, one in the values, values-v11, and values-v14 folders respectively. The default styles.xml sets
<style name="AppBaseTheme" parent="android:Theme">
the styles.xml in values-v11 sets
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
and finally styles.xml in values-v14 sets
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
This worked nicely for quite some time. I've checked the appearance for gingerbread using an emulator and the Holo-theme on a Galaxy SIII.
But now, also the Samsung phone will only use the classic android:Theme, no matter what I set in the style.xmls. I've also tried to raise the minSdkVersion in AndroidManifest.xml to 16 and to set the Holo-theme in the default styles.xml. Cleaning up and rebuilding had no effect either.
The Holo-theme is happily ignored by the app, and I don't know where else I can try looking to fix things.
Any help or pointers are very much appreciated.
Update
If I replace
android:theme="#style/AppTheme"
in AndroidManifest.xml with
android:theme="#style/AppBaseTheme"
everything works fine (AppBaseTheme is the platform-dependent parent theme for the customized platform-independent AppTheme). It somehow looks as if the Android runtime is lazy and does not care to look for the the most specific version of AppBaseTheme, but always takes the one found in values/styles.xml
Finally, after several unsuccessful cleans I took a different approach and tried to rename AppTheme to MyTheme (and updating the reference in AndroidManafest.xml accordingly). Now the app references the correct AppBaseTheme for each version of Android.