我刚从IOS开始android开发,又碰到了一个问题。
经过一天的尝试,我决定我将询问堆栈溢出的人
所以我的问题是:
我有一个应用程序,在行动栏(默认无夏洛克)我想要1个标志和2行文字。
通过互联网,我找到了动作栏的setCustomView。
自定义xml已加载,但我无法获得正确的布局
因此,我首先设置操作栏:
私有void setupActionBar(){
ActionBar ActionBar=getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
LayoutParams lp1=新的LayoutParams(LayoutParams.MATCH\u父级,LayoutParams.MATCH\u父级);
查看customNav=LayoutInflater.from(this).充气(R.layout.actionbar,null);//包含按钮的布局。
actionBar.setCustomView(customNav,lp1);
}
而不是xml:
<;?xml version=“1.0”encoding=“utf-8”?>;
<;LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:layout\u gravity=“fill\u horizontal”
android:orientation=“水平”
android:background=“@color/Blue”>;
<;文本框
android:id=“@+id/text\u左”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:text=“@string/title\u菜单”
android:textColor=“@color/White”
android:paddingLeft=“5dp”
android:layout_gravity=“left”/>;
<;图片框
android:id=“@+id/图标”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:src=”https://stackoverflow.com/questions/20972324/@可绘制/图标“
android:layout_gravity=“center”/>;
<;文本框
android:id=“@+id/text\u right”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:text=“@string/title\u帮助”
android:layout\u gravity=“右”
android:textColor=“@color/White”
android:paddingRight=“5dp”/>;
</线性布局>;
但结果却不是我想要的:
那么,我忘记了什么/做错了什么/我应该做什么
尝试将根布局更改为相对布局
<;RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:layout\u gravity=“fill\u horizontal”
android:orientation=“horizontal”>;
<;文本框
android:text=“左文本”
android:layout_-toLeftOf=“@+id/图标”
android:layout\u alignParentLeft=“true”
android:id=“@+id/text\u左”
android:gravity=“左”
android:layout\u width=“匹配父项”
android:layout\u height=“包装内容”
android:paddingLeft=“5dp”/>;
<;图片框
android:layout\u centerHorizontal=“true”
android:id=“@+id/图标”
android:layout_width=“10dp”
android:layout\u height=“包装内容”
android:src=”https://stackoverflow.com/questions/20972324/@可绘制/背景为“日出”
android:layout_gravity=“center”/>;
<;文本框
android:text=“Right txt”
android:layout_toRightOf=“@+id/图标”
android:id=“@+id/text\u right”
android:layout\u width=“匹配父项”
android:gravity=“右”
android:layout\u height=“包装内容”
android:layout\u gravity=“右”
android:paddingRight=“5dp”/></相对寿命>;