android actionbar 在底部,将我的ActionBar放在底部

创建自定义底部工具栏

我已经创建了一个简单的应用程序,它应该向您展示如何开始

47a4f0dbc2b929bda5fe6d8382666c38.png

d3c7f6d8e6616ff71b253d40d056922b.png

创建自定义ViewGroup

这是我的activity_main.xml布局文件:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="0dp"

tools:context="com.example.piotr.myapplication.MainActivity">

android:id="@+id/show_pdf"

android:layout_width="match_parent"

android:layout_height="40dp"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:background="@color/primary_material_light"

android:orientation="horizontal">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_cut_mtrl_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_copy_mtrl_am_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_selectall_mtrl_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_paste_mtrl_am_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_share_mtrl_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_selectall_mtrl_alpha"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:src="@drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="75dp"

android:ems="10"

android:inputType="textPersonName"

android:text="Name"/>

正如你可以看到我的父母ViewGroup是RelativeLayout,它只是允许我创建在屏幕底部的视图.

请注意,我将布局填充设置为零(我认为:此处将布局边距设置为零是不必要的,效果相同).如果您更改它,工具栏将不会使用全宽,它不会粘在屏幕的底部.

然后我添加了一个带有硬编码高度的线性布局,它是:

android:layout_height="40dp"

我想要它,我的底部工具栏将采用完全可用的宽度,所以我将其设置为match_parent.

接下来,我ImageButton使用Android库中的图像添加了一些视图.

那里有两种可能性:

如果你真的想拥有一个像上面例子中的工具栏,只需在每一个ImageButton视图中删除这一行:

android:layout_weight="1"

删除重量和一些按钮后,您将获得与预期非常相似的视图:

6e859c6ce4e3dbd0b6f8bbe0b534bda2.png

如果你想获取整个宽度并使你的项目中使用相同大小的每个按钮,weight就像在我的例子中一样.

现在让我们转到我的AndroidManifest.xml

xmlns:android="http://schemas.android.com/apk/res/android">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

android:name=".MainActivity"

android:windowSoftInputMode="stateVisible|adjustResize">

在我添加的文件中,您只能看到一行:

android:windowSoftInputMode="stateVisible|adjustResize">

确保设备键盘不会隐藏我的自定义底部工具栏.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值