change action bar direction to right-to-left - android

I'm creating an android app for a right-to-left specific language. And I'm using ActionBarSherlock (a compatible android action bar library).
The thing I exactly want is how to change the direction of action bar to RTL even the user not sets the default Locale an RTL language.
If anyone has an idea even for standard android Action Bar it's valuable and may help please share it.
Thanks

From Android API Level 17+ it supports RTL natively. To force your entire layout to be RTL including the ActionBar do the following.
Edit your AndroidManifest.xml and add android:supportsRtl="true" to your <application> tag and then add the following line to the top of your Activities' onCreate() method forceRTLIfSupported(); and then insert the follow function into your Activity.
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
Of course that's only helpful for debugging. Use View.LAYOUT_DIRECTION_LOCALE for production builds so your layout is only changed when the user chosen system location/language aka locale supports RTL.

use this, It will be make layout from rtl but this in parent root of your xml
android:layoutDirection="rtl"
android:textDirection="rtl"

We must believe a powerful rule in programming:
Everything will be possible when you know your tools.
So, from now you can use this library to truly RTLize your actionbars:
https://github.com/semsamot/ActionBarRTLizer
And of course it is compatible with API Level 7+ .

Booger is right. The "Nabz Bazar" app that you mentioned does not align to the right on every version of android. As you can see here ABS doesn't really do anything on Android 4.0 or newer and the screenshots of that app are on a 4.2 android.

I am pretty sure you will not be able to do what you are asking. The ActionBar pattern is very specific, and the libraries supporting it would support the defined pattern only (which is having the icon on the top-left, then laying out title, and action buttons to the right).
Changing the test is as simple as changing the locale and text within your app (as you already alluded to).
Changing the position of the elements within the ActionBar itself will not be supported by the libraries that support the standard ActionBar pattern - as what you describe is not a supported UI pattern.
I think you should leave the AB as-is. It is not necessary to switch the order, as there is no right-left orientation anyway -and changing this will be extremely jarring to your users.
Bottom line, you won't be able to to this with the existing libraries - and you probably shouldn't anyway.

You can use one or all of them if your project is completely RTL language.
set on AndroidManifest.xml
<application
android:supportsRtl="true"
>
set in Xml.file
android:layoutDirection="rtl"
android:textDirection="rtl"
set in java.class
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}

Kotlin:
Add forceRTLIfSupported() to the top of the onCreate() method of your Activity and then insert the following function into your Activity:
fun forceRTLIfSupported(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
window.decorView.layoutDirection = View.LAYOUT_DIRECTION_RTL
}
}

Related

Force RTL layout direction not working

I am trying to add RTL support in my app where layout direction should also change to RTL on force setting to RTL.
I have followed:
Set minSdkVersion to 19 ,
Added android:supportsRtl="true" to application tag in AndroidManifest.xml,
Switched left/right attributes to start/end
Followed this link.
However, even when I use the "Force RTL Layout Direction", my app doesn't display the RTL layout. The system UI is flipped to RTL, and other apps also support RTL.
Is there anything else that need to be done?
in manifest.xml
add android:supportsRtl="true" in tag
and in every activity add this line in onCreate method
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
There is a much easier way to do the above changes without going through all the files and then doing it manually. Android Studio can do this for you.
Just go to Android Studio > Refactor > Add RTL support where
possible…
or
try to use this link :
link
Found the reason:
was using older version of mixpanel library
compile "com.mixpanel.android:mixpanel-android:4.6.0"
updated to latest version
compile "com.mixpanel.android:mixpanel-android:5.4.0"
hence ,check the libarary version,n update to latest.

Android Action bar direction RTL

I try what simon tell to do for change direction but it's doesn't working.
It's seems that for hundredth of a second it's work but when Action bar add the action buttons it's put the buttons at left instead at right.
What can be the problem? it's seems that somewhere in nmy code had line that tell freamwork to do otherwise?
The RTL value (true or false) is included in the flags in getApplicationInfo.flags.
As a long shot - is it possible that you are somehow changing the value?
The ability to set RTL was added in Android 4.2 if you are supporting this OS level or higher, this will be easier for you to accomplish.
Proof it is 4.2+: https://groups.google.com/forum/#!topic/actionbarsherlock/-npidM2Eo0w
Google post outlining how to change to RTL: https://plus.google.com/+AndroidDevelopers/posts/HuHNSb8V7s8
Otherwise, I would reference the SO question already pointed to in another comment if you are supporting an OS level older than 4.2: How to handle RTL languages on pre 4.2 versions of Android?

AIR for Android: toggle SYSTEM_UI_FLAG_HIDE_NAVIGATION

I want to toggle SYSTEM_UI_FLAG_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LOW_PROFILE flag when compiling with AIR for ANDROID, but I don't know how to to this. Probably I had to modify the name_of_app.xml ...
I want to 'try' to switch off the menu bar in an Android Tablet, but every methods I try are a mess ....
Any Help ??
Massimo
If you want to remove the statusbar (the bar at the top), you need to go fullscreen. You can do this either in your app.xml by setting <fullscreen>true</fullscreen> or in your app at runtime by setting stage.displayState = StageDisplayState.FULL_SCREEN;
If you are trying to hide the menubar (the soft-navigation present at the bottom of Nexus devices and a limited number of other Android devices), this will set those buttons to be in their minified state as well (they are not hidden, but are set to a simple glowing circle rather than the icon). I do not know if it is possible through AIR to hide the menubar completely. It should be possible using an AIR Native Extension, assuming it is possible at all, but that may (likely is) more trouble than it is worth for such a simple task.
For future reference, you can't set most Android flags through AIR. It simply is not supported. You can set uses-permission and uses-feature in your app.xml as Manifest additions, but that is it.

developer.android.com training actionbar - correct result?

I am currently following the tutorials on http://developer.android.com/training/index.html.
I have completed the first section and continued the second section on the same code.
In the tutorial the goal is to make an ActionBar.
I have chosen to support android 2.1 and above using the v7 appcompat library.
I assume it is installed correctly (and have followed this thread).
My question is, what is my result supposed to look like?
I have created 2 AVD's, one running API 18 and one running API 8 and am testing on my own phone (Xperia Ray running Cyanogenmod 9, which is API 15 I believe)
All 3 devices give different results.
The AVD running API 18 shows the app with an actionbar in both the main activity and a secondary activity. Pressing the logo in the Actionbar in the second activity returns to the parents activity.
The Xperia Ray phone (API 15) also shows the actionbar in both activities but does not return to the parent activity after being pressed. I suppose I still need to program that and is not standard in API 15?
The AVD running API 8 shows an actionbar in the main activity with the name of the app but shows no actionbar in the second activity.
This is the code I used, from the tutorial linked above:
public class MainActivity extends ActionBarActivity { ... }
and in the manifest in the < application > tag
android:theme="#style/Theme.AppCompat.Light"
Should this be enough to make an actionbar appear in lower versions of android or is it supposed to not show an actionbar besides the main activity in lower versions?
I'd like to fix this before continuing the tutorial.
If my question needs more clarifications, I'd be happy to provide it. All help is appreciated. Thanks!
I have no experience with AppCompat, but I recommend ActionBarSherlock appCompact, is very easy to use. Link: http://actionbarsherlock.com/
You can also customize the style with: http://jgilfelt.github.io/android-actionbarstylegenerator/
good luck ;)
I found what I did wrong.
Following the tutorial litterally, the second activity will not have an actionBar.
In each of the activities java file, the class must extend ActionbarActivity instead of Activity. (The tutorial only explicitly tells to change the main activity)
--> This makes an action bar appear in every activity.
To make the back or home button appear in all versions, I did it like this:
//Make sure we're running on HONEYCOMB or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT >= 7 ) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //for older versions
//getSupportActionBar().setHomeButtonEnabled(true); //without arrow
}
The first if statement should already be there by default (I commented it out as it was left out some of the code examples in the tutorial. Leave it in!).
getSupportActionBar() needs to be used on older APIs (make sure the appcompat library is included correctly). Using getActionbar() on older APIs causes a Forced Close.
Using setHomeButtonEnabled() works too but is without the < icon in the action bar.
Thank you for the replies. If anyone has other suggestions or tips, they are always welcome. (are both if statements needed?)

Android - Action bar at top and tabs at bottom of the page

I am a novice Android developer. I have just started learning Android programming. I want to know whether it is possible to add Action Bar with Action Icons at top of the page and Tabs at bottom of the page! If so someone please guide me how to implement a code for it!
Thanks in advance,
UDAY
AFAIK, you can add action buttons on the bottom, only if there is no room at the top, however to do this, you should activate "split" option of your action bar in activity:
To enable split action bar when using the support library, you must do two things:
Add uiOptions="splitActionBarWhenNarrow" to each <activity> element or to the element. This attribute is understood only by API level 14 and higher (it is ignored by older versions).
To support older versions, add a <meta-data> element as a child of each element that declares the same value for "android.support.UI_OPTIONS"
This is quote from official docs, I recommend you to read more on http://developer.android.com/guide/topics/ui/actionbar.html
By the way, if you want to support older versions of android sdk (less than 3) use ActionBarSherlock it is third-party lib, but it has very similar ip to official actionbar and supports any version of android sdk. To learn more about it visit actionBarSherlock Home Page
To answer your question: Yes
Read android documentation about Actionbars
http://developer.android.com/guide/topics/ui/actionbar.html
And you see there is something called Bottom bars.
They should not be used for navigation tho as you can read on at
http://developer.android.com/design/patterns/pure-android.html

Categories

Resources