[英]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.