What's wrong with the ICS Holo Dialog theme? - android

I've come across a bit of a weird issue with activities using the Holo Dialog theme (#android:style/Theme.Holo.Dialog) in Ice Cream Sandwich.
It seems like they ignore their layouts and fill the entire screen instead of the layout width and height from their XML layouts. The same layouts are working as expecting in Honeycomb, but not on Ice Cream Sandwich.
Example:
The correct way (Honeycomb)
The incorrect way (Ice Cream Sandwich)
Both devices are running the exact same version of the application, and are using the exact same layout. Here's the layout in question:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="940dp"
android:layout_height="600dp"
android:layout_margin="10dp" >
<GridView
android:id="#+id/gridView1"
android:layout_width="940dp"
android:layout_height="600dp"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
Any ideas to how this can be solved? A similar issue occurs on my ICS-based Galaxy Nexus, which completely ignore the match_parent tag for height and width. Is the dialog theme broken in ICS?
Update:
I've done some more testing, and it seems like 894dp of width or less will produce the "correct" look, but if I set the width to 895dp or more, it'll be the incorrect look. The emulator's acting the same way. This is extremely weird...

I don't think it is true that ICS discourages dialogs. Indeed, they have a whole page at Android Design. What is true is that DialogFragment (which is even provided in the Android Support library) is preferred over the legacy Dialog.
I corroborate your observation about the dialog popping to full-screen, but the behavior is device-dependent. On my Xoom tablet it happens at 915dp, not 895. On my Galaxy Nexus, it happens at 444dp. And on my Galaxy Tab 10.1, it does not happen at all.
If you dig into the source, you can see that there is a Dialog theme that is descended from Holo for smaller screens and from Holo.Dialog.FixedSize for larger ones. I would have expected this to be based on display size, not layout size, but perhaps I would be mistaken. I'll try to figure out what causes the jump.

I couldn't find an answer for this myself, so I eventually dropped the dialog theme and instead used a full-width standard theme layout. I think ICS discourages the use of dialogs, so maybe that's why it's changed.

All version of Android ignore the width/height of a Dialog themed layout xml.
To fix this, after calling:
setContentView(R.layout.contacts_preferences);
add a line:
getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
or WRAP_CONTENT for your needs.

Try swapping your LinearLayout for a RelativeLayout. That will do the trick :)
Somehow LinearLayouts always fills the screen when displayed in a dialog. RelativeLayouts don't.

Related

?android:attr/actionBarSize not working in only one device. Why?

Android experience level: Novice.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
android:padding="10dp"
android:fillViewport="false">
I have applied top margin to the ScrollView which is the height of actionBar. That works well in two of my physical devices properly but not in one. Why the one device does not utilize the value?
Screenshots attached.
Lenovo A7000 with Marshmallow 6.0 Stock ROM:
Below the action bar, one or two lines are not visible. Probably behind the actionBar.
HTC phone and Samsung tablet: The text appears fine.
Try changing attribute value to ?attr/actionBarSize rather than using ?android:attr/actionBarSize

Android text overflow

I have one problem with text overflow.
I have searched all the topics about this problem and tried everything but none work for me(android:singleLine etc..).
To be more specific,text is showing in a single line,in textview,in listview even in alert dialog without custom layout.
The strange fact is that in alert dialog is showing only the first time,if i open again the dialog its ok.But the problem persists in lists and textviews......
The most strange part is that sometimes text is overflowing even in other AVD but later are OK,but in QHD and in my phone(HTC DESIRE) is overflowing.In Graphical Layout is looking fine in every configuration.
One layout of the many layouts that have problem is that:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:fadingEdge="none"
android:fastScrollEnabled="true" >
<!-- Preview: listitem=#layout/listview -->
</ListView>
</LinearLayout>
This problem appeared now,i didnt have it before...i dont know what is causing this because i have update ADT Tools,JDK and i replace my custom Action Bar with ActionBarCompat from ApiDemos.
What is should do?Why this is happening?Maybe is ActionBarCompat fault??
EDIT:
I have attached a screenshot of dialog overflow problem(1 of 2)
To be honest I suggest using a custom alert dialog since languages other than English is not properly measured. Imagine a box [a] where a holds a character, it gets measured on the width of that character. However android doesn't have the width of other characters other than English. I know this because I also work with other languages on android, it messes up my view so what I did was compromise with the text data. Sorry didn't see your view before posting my previous answer.
I found the solution.It was the ActionBarCompat from API Demos that make all these problems!!!After so many days trying to find out,was the ActionBar!!!!!!I reported the issue and i hope to fix that soon!The problem is that i changed
<style name="AppTheme" parent="android:style/Theme.Light">
to
<style name="AppTheme" parent="android:style/Theme.Holo">
in styles.xml and cause that bug.

Android: How to add a vertical progress bar to a home screen widget?

I need to put a vertical scroll bar in a home screen widget, and after searching many times, I can't find a convenient solution that works on API3 and above!
I tried many solutions:
- using bitmap created at run-time, but on some displays it never reach 100%
- a patch9 bitmap, but the scroll bar display gets completely messed up when the progress is near 0.
- using the addView() with 100 existing layout and it works great, except it's only available since API7!
- including all 100 layouts and showing only one at a time, work fine, but what a mess to include those in my 8 different widget layouts!
I tried to use the weight programmatically but it's not possible either, any other solution to resize a view based on a %?
Here is one progress bar layout I currently use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="#drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
Only solution I found so far is to have all the possible progress levels ready to use in various Xml layout files.
On Android API < 7, all those need to be included in a single xml layout and shown/hidden at run-time, while on Android API >= 7, one can actually use addRemoteView() to include the desired layout in a much more efficient way!
You should use ScrollView! You must place this within a layout. By default, scrollview is for Vertical Scroll. If you want horizontal scroll you must specify HorizontalScrollView. Hope this helps

How to keep background image size when software keyboard show

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

dividers between TabWidgets

Is the android:divider attribute under the TabWidget working? I tried the Tab Layout tutorial from android just to test (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and set the android:divider to some image (for now I used the android vertical scrollbar as the drawable to really emphasize if its getting picked up (copied it from frameworks), but when I ran it on the emulator, it doesn't appear to be working. According to the docs, the TabWidget does seem to support this attribute: "Drawable used to draw the divider between tabs."
Can anyone help? I am using a nine-patched drawable as my divider image drawable.
MB
It doesn't look like the divider attribute is available anymore for TabWidget. One way to add a custom divider is to set it programmatically:
mTabHost.getTabWidget().setDividerDrawable(R.drawable.divider_vertical_dark);
Make sure however, you call this before you set the content of the tabs. It would crash on me if I called it after.
I had the problem in ICS, where divider was visible. None of the solutions worked except for the following.
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:fadingEdge="none"
android:showDividers="none" >
</TabWidget>
Key line was android:showDividers="none"
I had this issue and solved it with the following code
tabHost1.getTabWidget().setDividerDrawable(R.drawable.example1);
if(Build.VERSION.SDK_INT >= 11)
tabHost1.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE);
For api levels below 11, it worked with the first line. For 11 and higher I included this to get this working. setShowDividers is added in linearlayout from api level 11. Hope this helps someone
Having the same issue myself. I only see the problem in Ice Cream Sandwich (ICS / 4.0.x). In android 1.6 - 2.3.4 there is no issue, dividers show up properly when setting a drawable in code, or in the xml layout.
I've tried just about everything I can think of to fix it but nothing works, including Josh's answer above :( though I have noticed that when setting any drawable as the divider, it will take up the space between tabs as if there was a drawable there, but it's just not visible.
Hopefully that gives someone else a hint as to what could be happening..?
I removed divider line from tabbar with use of below magical lines.
mTabHost.getTabWidget().setDividerDrawable(null);
OR
mTabHost.getTabWidget().setDividerDrawable(R.Color.transperant);

Categories

Resources