我已经创建了如下所示的操作栏。
程序语言是RTL。我使用以下代码更改了它:
@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);
}
}
并且在onCreate()
中使用了以下代码:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setIcon(R.drawable.actionbar_icon);
getSupportActionBar().setTitle("سیکاس");
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff378417));
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
黄色图标是Drawable
。
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/ic_launcher"
android:gravity="left"
android:top="5dp"
android:left="8dp" />
</layer-list>
如何使黄色图标显示在操作栏的左侧?
为操作栏添加自定义布局,
setSupportActionBar(toolbar);
LayoutInflater mInflater=LayoutInflater.from(context);
View mCustomView = mInflater.inflate(R.layout.toolbar_custom_view, null);
toolbar.addView(mCustomView);
更改
android:gravity="left"
with
android:gravity="end"