我是一个 Android 新手,所以如果这是一个新手问题,请原谅我。
我试图在屏幕顶部有一些菜单,并且希望它出现在我的应用程序内的每个 Activity 中。
现在我的问题是如何实现这个目标?我应该创建一个 XML 并将其包含在每个地方,还是应该有一个基本 Activity 并在其中托管我的其他 Activity ?
更新:看看下面的屏幕截图,我想要完全相同的。如果您注意到,您会看到两组按钮,一组在顶部,另一组在底部。中间的屏幕是可滚动的。
最佳答案
在 Android
诸如顶部菜单之类的东西不存在。引用自CommonsWare
There is no "top bar menu" in Android, assuming you are referring to something like the bar at the top of an Windows window or the OS X screen. You are welcome to create something of your own, but there is no built-in platform support for such a concept.
Spend some time with existing Android applications, and you will find few (if any) that implement a "fixed visible menu on top". If you find one that does, post some screenshots of it in action and perhaps we can make some suggestions on how to implement it.
所以更新后你需要了解一些关于实现actionBar的知识。 所以请查看这些链接
actionbarsherlock , johannilsson / android-actionbar , cyrilmottier / GreenDroid
并添加Buttons
到底部,您应该使用 <RelativeLayout>
,将边距添加到 Buttons
底部的按钮你可以像这样设置类似
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#3B3B3B"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Second"
/>
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Second"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="67dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Second" />
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
关于android - 如何在android中拥有全局菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967732/