I have a LinearLayout and on some devices all the views are reversed.
The Good Version:
[b1] [b2] [b3]
On some devices:
[b3] [b2] [b1]
Why does that happen and how can I fix it?
If you're targeting and testing on API level >=17 (i.e. Android 4.2) this might be caused by RTL support, as described here.
If you don't want this, you can either change android:layoutDirection for each particular view (and since the default is inherit, the root view should suffice) or you can disable it for the whole application by setting android:supportsRtl="false" in the AndroidManifest.xml file.
Or, you could also target an API level < 17, since it will then be disabled for compatibility (but this would lock you out of certain APIs).
Related
i made this android:supportsRtl="false" for my application
and yet it still flip my layout views when i change the language from English to Arabic and verse versa any clues what to do to prevent the views from flipping not matter what language it runs on or API level
thanks
If targetSdkVersion is set to 16 or lower then it will ignore the RTL support. Otherwise if you change the language then it will support RTL.
As this attribute is supported from the API 17.
Ref Link: https://developer.android.com/guide/topics/manifest/application-element
I need to know what actual difference between TextView and TextViewCompat.
When we should use TextViewCompat?
In much the same way as other compatibility classes, it exists to provide backwards compatibility for new functions to older versions of Android.
If you compare the two, you will see the difference.
One such example is getMaxLines(). In an ordinary TextView, this requires SDK level 16. TextViewCompat introduces such functions for SDK levels from 4.
define TextViewCompat in developer.android
A TextView which supports compatible features on older version of the platform, including:
Supports textAllCaps style attribute which works back to Gingerbread.
Allows dynamic tint of it background via the background tint methods in ViewCompat.
Allows setting of the background tint using backgroundTint and backgroundTintMode.
I have a fragment where on onCreateView() I set its root view's paddingTop programmatically to show it below an overlay actionbar. I simply call:
root.setPadding(0,
Math.round(getResources().getDimension(R.dimen.abc_action_bar_default_height_material)),
0, 0);
This works great on all devices I test until I build the apk with proguard. Then only on devices running API 16 (so far that I tested), the padding doesn't get updated and the root view goes under the actionbar.
I tried many changes to my proguard configuration to no avail. The latest try follows this configuration adding exceptions to all views and support libraries.
I also changed the code to add a log on my onCreateView() and I can see it on my console with the right padding value to be updated. It just doesn't show on the UI only for these devices on API 16.
And the fact that it works when debugging, makes finding a solution for this that much harder. Any ideas?
Use getDimensionPixelOffset instead of getDimension
I am trying to implement an action bar with tabs as navigation options. To do that I select the "Tabs+Swipe" option in the "New Blank Activity" section of the "New Android App" wizard as shown below.
Now, in the android manifest, when
android:targetSdkVersion="15"
which is the default value, the action bar looks like this on a Nexus 7/Nexus 7 emulator, this is the desired look of the app
Now when I change that line in the android manifest to
android:targetSdkVersion="16"
the look of the action bar changes to this
The default look remains for any version of android but 16, can anyone please explain why the look of the action bar suddenly changes when the targetSdkVersion is set to 16?
The above is reproducible in the emulator as as well as on a real nexus 7.
Full screengrabs for
Normal: http://i.stack.imgur.com/VsBA2.png
After android:targetSdkVersion="16": http://i.stack.imgur.com/OM6Y4.png
Update-10th March, 2013: Switched to the List Navigation mode (instead of Tabs) to enable move to android:targetSdkVersion=17
The reason it changes when setting targetSDK to 16 is because Google changed how tabs are measured in Jelly Bean. Specifically, look at this in android.internal.view.ActionBarPolicy:
public boolean hasEmbeddedTabs() {
final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
}
// The embedded tabs policy changed in Jellybean; give older apps the old policy
// so they get what they expect.
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
}
However, I suspect you don't just want the reason, but a solution. Unfortunately, I can't give you a straightforward way to set it to only embedded.
I can suggest using ActionBarSherlock to make it consistent, though. The bonus to that is the ability to use actionbars on older devices. When using it(portrait), I can confirm that if you set the targetSDK to 16, it uses the stacked layout on Jelly Bean, Ice Cream Sandwich, GingerBread, and Froyo. At least you will be able to design your layout while knowing what to expect.
Keep in mind that in most cases, switching to landscape mode will embed them in the actionbar again, since there is "enough room" the way it measures.
I have an edittext in my application that will show the cursor correctly in Froyo or Gingerbread, however in later sdks the cursor is invisible. I have found online the solution is to set the android:textCursorDrawable="#null" so that the edittext will use the font color for the cursor. However, since my minsdkversion is 8, I do not have access to that property.
Is their either a way to selectively add a property based on the sdk you are on? Or possibly a way to work around this so that I can have visible cursors on both older and newer sdk versions?
I don't know your current setup, but one way to use that property is to use different layouts folders based on various android versions. android:textCursorDrawable is a property introduced in API 12 so you could have a layout folder like layout-v12 which will be used where the API is 12 or greater. In the layouts from this folder the use of the property is valid.
For lower versions, Froyo and Gingerbread, you don't have any problems so you would use a default folder, layout. In the end you'll have two layouts folder(containing the same layout files):
layout // don't need the property
layout-v12 // use the property
That leaves out API 11, I don't know if this is a deal breaker for you.
Try setting your targetSdkVersion to API level 13 or higher to gain access to the android:textCursorDrawable property
If you not has a cursor I guess the input is simple and say you only can enter new chars at end of the text?
I think you can use a TextView and to this add you own KeyListener?
But in this case you will has problem with the virtual keyboard not is show, see some of this links:
Forcing the Soft Keyboard open
android force keyboard visible
or create you own keyboard if the rang of valid keys is very limit as only digits.