[英]Android change Action Bar icon position
我创建了一个如下所示的操作栏。
程序语言为 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"
和
android:gravity="end"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.