Setting android:windowBackground to #null makes scrolling to smear? - android

i'm using the sherlock actionbar library in order to support many devices . i have a viewPager which has 3 fragments :
one with a listView , each item has a textView and an imageView
the second has a gridView , each item has a textView and an imageView
the third just has a textView for now.
as i've heard in google IO videos (and since Lint tells me) , it's recommended to have the next style being used for all of the activities:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#null</item>
</style>
</resources>
this has worked for me on many devices .
however , on the emulator , using version 2.3.3 , and on galaxy nexus , when i scroll (either the viewPager or any of the adapterViews) , everything just smears , so i get a lot of white pixels as if nothing was refreshed.
i've even tried to set android:cacheColorHint="#00000000" for all of my adapterViews , but it still occurs.
what is going on? how can i fix this thing ? i like adding the above since it removes the ugly gradient background of galaxy S3 that appears for every app.

You should only set the background to nul if you cover it with something else. Either:
- Set the background to null in the theme and add a new background in your layout
or
- Set the background in your theme to the color/image you want.

Related

Android ViewPager very unusual behavior on scrolling between pages [duplicate]

i'm using the sherlock actionbar library in order to support many devices . i have a viewPager which has 3 fragments :
one with a listView , each item has a textView and an imageView
the second has a gridView , each item has a textView and an imageView
the third just has a textView for now.
as i've heard in google IO videos (and since Lint tells me) , it's recommended to have the next style being used for all of the activities:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#null</item>
</style>
</resources>
this has worked for me on many devices .
however , on the emulator , using version 2.3.3 , and on galaxy nexus , when i scroll (either the viewPager or any of the adapterViews) , everything just smears , so i get a lot of white pixels as if nothing was refreshed.
i've even tried to set android:cacheColorHint="#00000000" for all of my adapterViews , but it still occurs.
what is going on? how can i fix this thing ? i like adding the above since it removes the ugly gradient background of galaxy S3 that appears for every app.
You should only set the background to nul if you cover it with something else. Either:
- Set the background to null in the theme and add a new background in your layout
or
- Set the background in your theme to the color/image you want.

Why does setting android:background on a Button cause loss of L/R padding?

I am using Android Studio 2.2.1 with project with these settings:
compileSdkVersion 24
buildToolsVersion "24.0.2"
minSdkVersion 16
targetSdkVersion 24
If I use the GUI to change the button background, it adds this to the layout:
android:background="#color/colorPrimary"
Then, if I run the app on a 4.4 virtual device (Microsoft's Android Emulator because I'm on an AMD system and I want a fast emulator), or on a Samsung Galaxy S6 with Android 6.0.1, the button has the correct color but loses left and right padding and the text runs right to the left and right edge of the button.
If I set only the backgroundTint, then the button has the correct padding on the virtual device, but not the correct color. However, on the S6, it has the correct color and padding.
This seems like a bug somewhere, but where? Is it in the code generation or is this a bug in Android 4.4?
I think Android Studio should be doing whatever needed to make it work correct on both platform levels, whether it is as complex as some of these solutions:
Standard Android Button with a different color
or something more succinct.
My styles.xml file shows:
<resources>
<!-- Base application theme. -->
<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>
</resources>
and my AndroidManifest theme setting is:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
This seems like a bug somewhere, but where?
Right here:
android:background="#color/colorPrimary"
Is it in the code generation or is this a bug in Android 4.4?
No, it is your replacement background. It is a color, without any intrinsic padding, and without being wrapped in a StateListDrawable.
The stock background of Button widgets has some amount of padding enforced as part of the background itself (e.g., via some transparent pixels in the nine-patch PNG used for the background). The actual background itself is a StateListDrawable, which chooses one of several other drawable resources to apply based on the state of the Button (e.g., normal, pressed, focused, disabled).
To replace a Button background, you need to first use a StateListDrawable of your own. Otherwise, your Button will not appear to respond visually to click events or other state changes (e.g., being disabled). Then, you can either incorporate some padding into the backgrounds for your states, or put padding on the Button widget itself, as you see fit.
I think Android Studio should be doing whatever needed to make it work correct on both platform levels
Android Studio assumes that you know what you are doing. There is no hard-and-fast requirement that Button backgrounds have this sort of padding, and there is no hard-and-fast requirement that a Button be something that makes sense to users (versus "hey, why does this button seem to not respond visually when I tap on it?"). There will be scenarios where developers do want Button widgets to have no padding, such as in an implementation of a segmented-list-control sort of compound widget.
Personally, I think the decision to have some intrinsic padding in the Button background is regrettable. But, that's the way it was implemented back in Android 1.0, and Google has elected to maintain the approach, even with newer themes, presumably for backwards compatibility.
If I set only the backgroundTint, then the button has the correct padding on the virtual device, but not the correct color
I have not played with backgroundTint with appcompat-v7. It is possible that you are seeing a bug there. You might consider posting a separate question with a complete example, plus screenshots, to get more specific help with that particular concern.

Android marshmallow listview scrolling gets blurry

I have an android application which is running on production for several years. Lately, I have discovered a problem with a ListView in the app, that gets blurry while scrolling. The problem only occurs under Android Marshmallow.
Here is a screenshot of the ListView while scrolling
Any help would be much appreciated.
Thanks!
Preface: I posted a separate answer prior to this one, but that solution only worked on my MotoX. I later discovered it did not work for my Galaxy Tab A. The answer here seems to be more universal:
I was able to fix my scrolling blur by defining a separate ListView style for my application and specifying a different list divider. So, for my application theme I set this:
<item name="android:listViewStyle">#style/ListViewStyleNoBlur</item>
Where ListViewStyleNoBlur is defined as:
<style name="ListViewStyleNoBlur" parent="#android:style/Widget.ListView.White">
<item name="android:divider">#android:drawable/divider_horizontal_bright</item>
</style>
I specified these in a values-v23 resources folder so the change doesn't affect pre-Marshmallow devices.
My application theme is based off of android:style/Theme.Light, which is why my list view style's parent is android:style/Widget.ListView.White. My app min SDK is 8, which is why I'm using such an "old" theme. I also noticed that if I use a "newer" theme, such as Holo, the blur does not exist.
I also had this problem and, through trial-and-error, finally found a solution. Hopefully it will also work for you. This appears to be a bug in Marshmallow related to the scroll bar in list views. I had the following property set in my application theme, and removing this property fixed the blurry scrolling:
<item name="android:fadeScrollbars">false</item>
Using true instead of false also works, but is unnecessary since it is the default. I also discovered (through trail-and-error) that using android:fastScrollEnabled="true" causes the same blurring, but based on your scrollbar style, you do not appear to be using it.
In summary, don't use android:fadeScrollbars. If that doesn't fix your issue, try playing around with any other scrollbar-related styles you may be using on your ListView, bearing in mind these styles may be part of the view directly, or part of an activity or application theme.

Bigger text icons in Action bar

I have this design to achieve:
but the result I got is this:
As you can see I am asked to create the submit button much larger that it actually is, I've tried setting it as an image with no luck, also I've tried entering it as normal text and manipulate the theme but that didn't work either, I'm using the latest and greatest API 21 .. Lollipop.
here's the code to the item in my menu:
<item
android1:title="submit"
android1:id="#+id/userLoginSubmitActionBar"
app:showAsAction="always|withText"/>
Have you tried using android:actionLayout attribute of the <item> tag? It will let you set a custom layout to be displayed. You could use a TextView and set the text size appropriately :)
As for the arrows, if I am not wrong, < means up navigation while <- means presence of a navigation drawer, right?
This is really a hack I suppose but what the hell, here's my solution to my own contribution,
I've set
<item name="android:actionMenuTextAppearance">
to my own custom theme parenting from
<style name="myStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
and the damn thing worked like magic ! haha... thank u guys, really, no need for the drum rolls in the background :D

Autohide scrollbars when not scrolling in a ListView

In the new official Twitter app, the scrollbars in all the ListViews the app uses are hidden unless the user is scrolling through the list.
When you start scrolling, the scrollbars appear. When you stop, they fade out with an animation until they are gone completely.
I can't seem to find anything in the documentation that indicates this as being a standard feature.
Is this something included in the API? If not, anyone know how this might be done?
Confirmed : either use android:fadeScrollbars ( if you're API level 5 )
or try to use setOnScrollListener to check scroll status and hide/show the bars . Some code examples are in this thread:
how to detect Android ListView Scrolling stopped?
You can enable scroll bar fading for your entire app on API level 5 and newer via a custom theme and the fadeScrollbars style attribute by adding this to styles.xml:
<style name="Theme.App" parent="android:Theme.Light">
<item name="android:fadeScrollbars">true</item>
</style>
Then set the new theme for your application in AndroidManifest.xml:
<application android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:description="#string/description"
android:theme="#style/Theme.App">
Just be sure you're not overriding this global theme on individual activities. Earlier Android versions will safely ignore this unknown XML attribute and not fade the scrollbars.
I haven't used them yet, but you might play around with android:scrollbarDefaultDelayBeforeFade and android:scrollbarFadeDuration, available on all widgets (i.e., subclasses of View).
I followed Alex's answer and it worked using both the theme settings and through code.
GridView gridview = (GridView) findViewById(R.id.mygridView);
gridview.setScrollbarFadingEnabled(false);
I did encounter a problem however with the Gallery Component. Whilst the following will compile fine, it will throw a NullPointerException. I assume this is to do with a Gallery not having scrollbars to show/hide.
Gallery gallery = (Gallery) findViewById(R.id.myGallery);
gallery.setScrollbarFadingEnabled(false); // <-- this will throw an exception
Android 2.2

Categories

Resources