xml布局看起来很奇怪(操作栏中的“添加"按钮或图标) [英] xml layout look weird (Add button or icon in action bar)
本文介绍了xml布局看起来很奇怪(操作栏中的“添加"按钮或图标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在操作栏中添加保存button
,但是它显示在action bar
下方.
I want to add a save button
in action bar but it shows below the action bar
.
什么是正确的解决方法?任何帮助将不胜感激.
What is the correct to solve ? Any help would be greatly appreciated.
代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:theme="@style/Theme.AppCompat"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="match_parent">
<Button
android:id="@+id/save"
android:text="SAVE"
android:layout_width="wrap_content"
android:background="#000"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="16dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:background = "@drawable/img_receipt"
android:src="@drawable/upload"
android:scaleType="fitXY"
android:layout_width="270dp"
android:layout_height="290dp"
android:id="@+id/image" />
<TextView
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Add a description"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_marginTop="40dp"
android:id="@+id/textView"
android:layout_below="@+id/image"
/>
<EditText
android:layout_marginLeft="5dp"
android:layout_width="350dp"
android:paddingBottom="75dp"
android:paddingLeft="10dp"
android:layout_height="120dp"
android:hint="Add a description"
android:textColor="@color/black"
android:background="@drawable/roundedcorner_edittext"
android:layout_marginTop="80dp"
android:layout_below="@+id/image"
android:id="@+id/editText" />
</RelativeLayout>
屏幕截图
如您所见,保存按钮位于操作栏下方.我希望它放在健康的应用程序标题旁边.
As you can see the save button is placed below action bar. I want it place beside the healthy app title.
推荐答案
最后我明白了它的作用
在我的收据活动中,添加这两行
In my Receipt Activity, add these two lines
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
并将此行添加到 androidMainFest 中,以避免应用程序崩溃
and add this lines in androidMainFest to avoid the app cras
<activity android:name=".Receipt"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
这篇关于xml布局看起来很奇怪(操作栏中的“添加"按钮或图标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文