I appreciate there's a number of questions around this but none of them seem to resolve the situation I find myself in. I've written a small test case to see if the community can support.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#ff0000">
</RelativeLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="12dp"
android:text="Hello World!" />
</RelativeLayout>
This snippet above, produces the following: -
when given a theme in the android manifest for this activity of: -
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
So.. this is exactly what I would like, however when I open the keyboard, the following happens: -
(given that I have the following set in the manifest)
android:windowSoftInputMode="adjustResize"
As you can see, the keyboard hides the edit text.
This is where there's a number of other posts and confusion
The recommendations seemed to be to set things like (and see the result for each): -
android:fitsSystemWindows in the root relativelayout
Great, this fixes the keyboard hiding the edit text but now the red bar at the top is moved downwards, which is not what I would like (see original image if needed)
Change windowSoftInputMode to adjustPan
As expected, the view pans and the top bar is lost.
At this point, I'm a bit lost without coming up with a hacky solution to resize and calculate on the fly, which feels very dirty.
So given what I've posted above, does anyone have any solution to achieve the following: -
Translucent status bar (so the red panel sits behind it)
red panel doesn't disappear when the soft keyboard is shown
soft keyboard doesn't cover the text control
Let's also assume for arguments sake that colouring the status panel is not an option as I actually want to view the content behind the status panel, i.e. a map. I've used a red panel as an example.
I am developing an app with Android Studio 2.2.3 and I'm facing a problem I did not find before: if I add an Activity from a template such as Basic Activity, the newly created activity will let the device status bar display
If I add instead an activity from the Empty Activity template, no status bar shows up any more.
Reading through the layout files, I see that the Basic activity uses a android.support.design.widget.CoordinatorLayout whereas the Empty Activity uses a RelativeLayout. I cannot find any other differences, neither in the manifest. I programmed some apps with Eclipse some time ago and the status bar was there, even with the RelativeLayout, as far as I remember.
Any suggestion?
Thanks in advance, regards
Edit:
Status bar does not relate with layout. It is about the theme defined in the styles.xml. Can you check which theme is applied your activity?
Thanks steve for your suggestion: the behavior is due to
Yet another question: keeping this no-actionbar theme, why is my textbox not aligned with the top of the screen, like this:
My activity layout is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.pgsoftware.firebasepublisher.Main4Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test string"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"/>
</RelativeLayout>
and with the Layout inspector I get the following UI structure:
The LinearLayout at the top has a 72dp top-padding which I can't find digging into the themes: any suggestion?
Thanks in advance, regards
Please check the android:appTheme="#style/AppTheme" option in the manifest file . Check the theme option in res>style.xml file . Copy the stylesheet and paste in comment to see.
First of all, I know there are thousens of post asking the same, but after few days looking for a valid answer and try everything I'm still having the same problem...
So let's expose my situation:
I'm using ABS + google maps, so my map view xml is the following:
<?xml version="1.0" encoding="utf-8"?>
<com.actionbarsherlock.internal.view.menu.ActionMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0PGmnrCR70lothfjc_sFGTdFtESQPOksYKQWYpw"
android:clickable="true" />
</com.actionbarsherlock.internal.view.menu.ActionMenuItemView>
Few days ago everything was good, I was able to do my stuff in the app and everything. But suddenly I just made a little change, insert a framelayout to display more options in the screen. I tried to go back but was impossible...
I'm really deseparated, what can I do? maybe I can create a new project and paste all my code, but not really sure if it's going to work...
Any suggestions?
BTW my error code is this one
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'mapViewStyle' in current theme
java.lang.NullPointerException
Exception details are logged in Window > Show View > Error Log
Thank you for your time!
I finally solve the problem, the error in the screen is still there, but just like a warining and when I execute the app same to work fine.
The only think I made, is change the specific layout of ABS and put a frame layout.
The first time I noticed this was with AlertDialogs putting the entire message on the first line, even when I specified a new line("\n"). On ICS it displays the correct way, but for the life of me, I couldn't get it to work on GB.
Recently I've run into it again. I don't see any reason for it working fine on ICS but not GB and below.
EXAMPLE Project
Heres an example project with a textview, alertdialog, and two standard textviews.
https://github.com/T3hh4xx0r/Text-Example
EDIT
Heres the original question I asked. Seems the problem is more than I originally noticed though.
Android AlertDialog not displaying entire setMessage on certain devices
/EDIT
Here are visual examples of what I mean.
Even specifically setting multiple lines for the textView, the text is still one line, but with extra blank lines below.
Here is the layout that the alertdialog is using to create your view:
<!--
This layout file is used by the AlertDialog when displaying a list of items.
This layout file is inflated and used as the TextView to display individual
items.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/primary_text_light_disable_only"
android:gravity="center_vertical"
android:paddingLeft="14dip"
android:paddingRight="15dip"
android:ellipsize="marquee"
/>
As you can see the ellipsize is set to marquee, so I don't believe it was ever written with the intention to allow multilines.
There is a bug open at the moment that ellipse dots are never shown: http://code.google.com/p/android/issues/detail?id=10554
Therefore it is acting correctly.
If you want it to go onto multiple lines, create your own layout file and pass that to your dialog, that way you have more control anyway.
When the software keyboard shows, it resizes my layout and thus squeezes the background image together. My question is basically a duplicate of this question, which is explained in a very good way:
Software keyboard resizes background image on Android
However, that question was closed when they found a hack to solve it. I cannot use this hack. My entire layout is inside a ScrollView, and I need to be able to use this scrollview properly at all times. By using android:windowSoftInputMode="stateVisible|adjustPan" the user will not be able to scroll down and see the bottom of the screen while the keyboard is showing, since the layout will partly exist behind the keyboard. Thus the solution is unacceptable to me. Are there any better solutions out there?
Cheers,
I actually ran into a similar problem not too long ago. I stumbled upon the correct answer with a bit of work, though.
In your android manifest for this project, attached to the specific activity that you are using, use the line android:windowSoftInputMode="adjustPan|stateVisible" in the activity tag.
adjustPan basically means that your activity will not resize itself to fit the soft keyboard, and stateVisible means that the soft keyboard will show when requested (this can be stateAlwaysVisible, etc if necessary)
source :
Android Dev for Activity tags
After days of hardcore hacking I finally managed to construct a solution so advanced it might actually hurt to read it. I place an ImageView with the background behind the scrollview, and set scaleType="matrix" so it does not shrink when the keyboard is shown.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/black"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/mah_kewl_background"
android:scaleType="matrix"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<RelativeLayout
android:id="#+id/smsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PLUNX"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You can use the windowBackground property, which makes the drawable fit the whole screen.
To do that you need to:
1- Create a style:
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/you_bg_drawable</item>
</style>
2- Set your activity style in the AndroidManifest.xml
<activity
android:name=".ui.your_activity"
android:theme="#style/Background"/>
I was googling for a solution to this exact problem when I came across this, and after doing some research I found a solution I think is slightly better. Instead of hacking with a ImageView you can use this from your activity:
getWindow().setBackgroundDrawableResource(R.drawable.bg_my_background);
Hope it helps anyone else searching for a solution for this.
I can't comment on your answer but I'd like to add something.
I understand your dilemma and why the solution you linked to isn't a complete solution for your situation (since you can't scroll to the bottom of the view). I have a similar situation with a large scrollable EditText box. When the soft keyboard pops up I don't like my background getting squished.
I have tried your solution and while at first glance it appears to work, there are some situations where it might not be ideal:
If you allow your app the have a landscape mode, the background will not resize/stretch
If you run your app on a device with a larger screen or dpi, your background may not fill the screen
Basically it seems that when you set the scaleType to matrix you're telling Android to draw the background 1:1 and not to scale. So what's happening when you open the soft keyboard using your solution is, your scrollView and imageView are all getting resized as usual, but the image src you set remains 1:1 thus continues showing the same area.
So if for example your background image was set to a specific size (e.g. 480 x 800) and it perfectly fills your Nexus One, the moment you rotate to landscape you will have a black area along the right.
This is moot, of course, if your background is simply a repeating pattern, in which case you can make it extremely large and hopefully compensate for various screens (maybe even tablets).
Or you can also supply different backgrounds for different screen sizes/densities/orientations, but this still doesn't account for scaling.
In a vain effort to try and solve this, I stumbled upon a View attribute called android:isScrollContainer. This attribute tells certain views whether or not they are allowed to resize upon display of the soft keyboard. This is also mentioned by someone in your linked solution. I have tried setting this (to false) on the ViewGroup containing my background, but any child element that scrolls seems override it causing the squishing again.
As of right now I don't think there is a complete solution for our situation. Your's definitely works in some instances and I thank you for the effort. Hopefully Google will offer a solution in the future, but I don't think they would consider this a problem/priority.
Maybe there's another (really simple!) solution:
In styles.xml:
create a new style like this:
<style name="Yourstyle" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/mybackground</item>
</style>
AppBaseTheme is your normally used theme for your app.
Then you add in Manifest.xml:
<activity
android:name="com.your.app.name.Activity"
android:theme="#style/Yourstyle">
</activity>
So you have the same style but with a background.
Important: don't set any backgrounds in your normal .xml file!
It's my first post and I hope it helps and sorry for my English.
in Androidmanifest in activity tag use:
<activity ... android:windowSoftInputMode="adjustPan" ></activity>
check Android Developer reference
How about a solution where the 'background' is a Layout. Can we inflate a layout, make it the entire window size, then insert it as a window background?
After a lot of time searching...
Put android:windowSoftInputMode="adjustPan|stateVisible" in each Activitys