我正在使用 android 应用程序..我创建了一个网页视图。现在我想向我的应用程序添加顶部和底部菜单栏(如页眉和页脚)..我的应用程序以启动屏幕开始..然后是网页视图。我怎样才能将这些菜单添加到这些网络视图的顶部和底部..???请帮助我,谢谢。
这是我的xml
<?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:id="@+id/layout"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/appinc"
android:visibility="visible"
/>
<WebView android:id="@+id/webview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="gone"
/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="114dp" />
</RelativeLayout>
如果您正在使用选项菜单,则无法更改菜单的位置。请参阅:https://stackoverflow.com/a/8236188/2741586
但是,您实际上可以拆分操作栏(在 4.0+ 版本或更早版本中使用 mActionBarSherlock)。通过拆分操作栏,菜单将出现在顶部和按钮中,如下所示:.
如果这是您想要的:请按照此链接
更新: 我找到了另一个选择!如果你想要这样的菜单 如果您想要这些溢出 3 点图标:点击此链接。
如果这些都不适合您的需求,您可能应该创建自定义视图并根据您的选择进行修改!
希望这有帮助!
要在您的 xml 中应用,请尝试:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/appinc"
android:visibility="visible" />
<LinearLayout
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#550055" >
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottom_bar" />
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/progressBar1"
android:layout_below="@id/image"
android:visibility="visible" />
</RelativeLayout>
你应该使用 android:layout_weight="0dp"
Android 为我们提供了许多组件来制作快速且优质的应用程序。 TextView、ImageView等是android中通用且重要的组件。在本教程中,您将学习如何向 Android 视图的顶部和底部添加边框。 Android 视图的边框可以通过多种方式添加。在这里,我将展示向 Android [TextView、Button] 视图添加边框的最简单方法。所以,请仔细检查下面的内容/。
您需要在 res/drawable 目录中构建一个 XML 可绘制文件来添加边框。这适用于 android 2.2 及更高版本。
向 Android 视图的顶部和底部添加边框的分步指南
#1:XML 可绘制文件
首先,您需要在 /res/drawable 文件夹中创建一个 XML 可绘制文件 border_top_bottom.xml,如 /res/drawable/border_top_bottom.xml 并将其链接到 TextView。您的可绘制 XML 文件将如下所示。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#e10606" />
<solid android:color="#9bce64" />
</shape>
</item>
<item
android:bottom="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#9bce64" />
</shape>
</item>
</layer-list>
border_top_bottom.xml 由 GitHub 托管
#2:XML 布局文件
以下是我添加了 TextView 的 XML 布局文件的内容。
res/layout/top_bottom_border_in_android_view.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_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adding Border in Top and Bottom of View" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/border_top_bottom"
android:padding="30dp"
android:text="Top Bottom Border in TextView"
android:textColor="#000000"
android:textSize="18sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/border_top_bottom"
android:text="Top Bottom Border in Button" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="web"
android:gravity="center|bottom"
android:text="ViralAndroid.com"
android:textSize="25sp"
android:layout_marginTop="8dp"
android:textStyle="bold" />
</LinearLayout>
top_bottom_border_in_android_view.xml 由 GitHub 托管
#3:Strings.xml 文件
res/values/strings.xml
<resources>
<string name="app_name">Adding Border to the Top and Bottom of an Android View</string>
</resources>
strings.xml 由 GitHub 托管于 ❤
现在,运行“在 Android 视图的顶部和底部添加边框”应用程序,您将看到 TextView 的顶部和底部有边框。