在阿拉伯,波斯等RTL语言下,对于一些含有action button的UI虽然app使用了android:supportsRtl属性,但是仅仅是action之间的位置发生翻转,而每个button的Icon和Text位置却没调换。
比如(下图所示)未接来电的systemui下拉通知栏的icon和text位置没有调换
如果要调整其位置,可以通过setTextViewCompoundDrawables(int viewId, int left, int top, int right, int bottom)函数去实现想要的效果。
下面的修改是在波斯语、阿拉伯语下把action button的图片放到文字的右边。
Import java.util.Lcoale;
Notification.java(alps\frameworks\base\core\java\android\app)
private RemoteViews generateActionButton(Action action) {
final boolean tombstone = (action.actionIntent == null);
RemoteViews button = new RemoteViews(mContext.getPackageName(),
tombstone ? R.layout.notification_action_tombstone
: R.layout.notification_action);
//modify
String language = Locale.getDefault().getLanguage();
if(language.equals("ar")||language.equals("fa")){
button.setTextViewCompoundDrawables(R.id.action0, 0, 0,action.icon, 0);
}else{
button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
}
//modify
……
如果在其他地方要修改Button或者TextView的image和text的位置,可以直接调用TextView的函数setCompoundDrawables(Drawable left, Drawable top,Drawable right, Drawable bottom)就行。