改变操作栏方向从右到左 [英] change action bar direction to right-to-left

查看:130
本文介绍了改变操作栏方向从右到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从右到左的特定语言Android应用程序。而我使用ActionBarSherlock(兼容Android的动作栏库)。
的事情,我到底要的是如何改变操作栏到RTL的方向,即使用户没有设置默认语言环境的RTL语言。
如果任何人有即使是标准的Andr​​oid操作栏这是有价值的,可以帮助请与大家共享的想法。
谢谢

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

推荐答案

从Android的API等级17+它支持RTL本身。强迫你的整个布局是RTL包括动作条做好以下工作。

From Android API Level 17+ it supports RTL natively. To force your entire layout to be RTL including the ActionBar do the following.

编辑你的Andr​​oidManifest.xml中添加安卓supportsRtl =真正的<应用> 标签然后将下面的行添加到您的活动的onCreate()方法 forceRTLIfSupported()的顶部。键,然后将后续功能到你的活动

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);
    }
}

当然,这只是有助于调试。使用 View.LAYOUT_DIRECTION_LOCALE 生产建立这样的布局不仅改变当用户选择的系统位置/语言即locale支持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.

希望有所帮助。

这篇关于改变操作栏方向从右到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆