我刚从IOS开始进行Android开发,并再次茬问题。 经过1天的尝试,我决定我会问堆栈溢出的人。Android ActionBar自定义布局样式
所以我的问题:
我有一个应用程序,并在操作栏(默认没有福尔摩斯),我想1个标志和2行文字。 并通过互联网我发起了setCustomView的行动栏。 而自定义的XML被加载,但我无法得到正确的布局。
所以首先我安装操作栏:
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
View customNav = LayoutInflater.from(this).inflate(R.layout.actionbar, null); // layout which contains your button.
actionBar.setCustomView(customNav, lp1);
}
比XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal"
android:background="@color/Blue">
<TextView
android:id="@+id/text_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_menu"
android:textColor="@color/White"
android:paddingLeft="5dp"
android:layout_gravity="left"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/Icon"
android:layout_gravity="center"/>
<TextView
android:id="@+id/text_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_help"
android:layout_gravity="right"
android:textColor="@color/White"
android:paddingRight="5dp"/>
</LinearLayout>
但结果是什么事我不是在寻找:
那么我忘了/做错了什么/或者我该怎么做?
我爱你,它的完成我细腰1天。现在我可以继续。谢谢 – Msmit1993
不客气^^ –
谢谢这很有用。如果您需要不同的布局,请始终以root身份使用RelativeLayout! – Gibberish