简体   繁体   English

Android 更改操作栏图标位置

[英]Android change Action Bar icon position

I have created an Action bar like the following.我创建了一个如下所示的操作栏。

在此处输入图片说明

The program language is RTL.程序语言为 RTL。 I have changed it using the following code:我使用以下代码对其进行了更改:

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

And used the following code in onCreate() :并在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);

The yellow icon is a Drawable .黄色图标是一个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>

How can I make the make the Yellow Icon appear on the left side of the Action bar?如何使黄色图标出现在操作栏的左侧?

Add custom layout for the actionbar,为操作栏添加自定义布局,

setSupportActionBar(toolbar);
LayoutInflater mInflater=LayoutInflater.from(context);
View mCustomView = mInflater.inflate(R.layout.toolbar_custom_view, null);

toolbar.addView(mCustomView);

Change改变

android:gravity="left"

with

android:gravity="end"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM