Joe*_*eyL 7 xml android android-actionbar
我遵循了关于在我的应用程序中获取动作栏的教程.但即使我放入android:uiOptions="splitActionBarWhenNarrow"我的Manifest文件,它仍然保持在顶部.任何人对如何处理此代码有任何想法?
XML:
<LinearLayout 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:orientation="vertical"
android:background="#f0f0f0"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/myFragments"
android:layout_width="match_parent"
android:layout_height="0dp">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alotoftesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
根据这个评论:
你的ActionBar中有多少个菜单项?如果菜单项不适合顶部,splitActionBarWhenNarrow选项基本上允许溢出到底部的第二个"拆分"操作栏.如果所有菜单项都放在顶部,您将看不到拆分布局.
如果您想要一个自定义底部工具栏,请检查我对这个问题的回答(在下面添加):
创建自定义底部工具栏
我已经创建了一个简单的应用程序,它应该向您展示如何开始
![]()
创建自定义ViewGroup
这是我的
activity_main.xml布局文件:Run Code Online (Sandbox Code Playgroud)<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"> <LinearLayout 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"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_cut_mtrl_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_copy_mtrl_am_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_selectall_mtrl_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_paste_mtrl_am_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_share_mtrl_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_selectall_mtrl_alpha"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/> </LinearLayout> <EditText 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"/> </RelativeLayout>正如你可以看到我的父母
ViewGroup是RelativeLayout,它只是允许我创建在屏幕底部的视图.请注意,我将布局填充设置为零(我认为:此处将布局边距设置为零是不必要的,效果相同).如果您更改它,工具栏将不会使用全宽,它不会粘在屏幕的底部.
然后我添加了一个带有硬编码高度的线性布局,它是:
Run Code Online (Sandbox Code Playgroud)android:layout_height="40dp"我想要它,我的底部工具栏将采用完全可用的宽度,所以我将其设置为
match_parent.接下来,我
ImageButton使用Android库中的图像添加了一些视图.那里有两种可能性:
如果你真的想拥有一个像上面例子中的工具栏,只需在每一个
ImageButton视图中删除这一行:Run Code Online (Sandbox Code Playgroud)android:layout_weight="1"删除重量和一些按钮后,您将获得与预期非常相似的视图:
- 如果你想获取整个宽度并使你的项目中使用相同大小的每个按钮,
weight就像在我的例子中一样.现在让我们转到我的AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)<?xml version="1.0" encoding="utf-8"?> <manifest package="com.example.piotr.myapplication" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:windowSoftInputMode="stateVisible|adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>在我添加的文件中,您只能看到一行:
Run Code Online (Sandbox Code Playgroud)android:windowSoftInputMode="stateVisible|adjustResize">确保设备键盘不会隐藏我的自定义底部工具栏.
我认为,如果需要,你也可以在底部放置标签.
如果您有任何疑问,请随意提问.
希望它有所帮助
谷歌默认操作栏在任何情况下都不会显示在底部.正如其他人所提到的那样,当设备很窄时,splitActionBarWhenNarrow只会ActionBar在屏幕底部放置一部分(如标签等).不幸的是,如果你想在屏幕底部实现类似ActionBar的接口,你必须自己实现它(快速搜索找到这个例子),因为我没有看到任何库为你做这个.
总而言之,我建议不要这样做,因为它违反了设计文档中的无缝设计原则,打破了用户对ActionBar类型控件所在位置的期望 - 一个Android用户理想地习惯于以某种方式做事,你会需要一个非常令人信服的理由来打破这种期望.
| 归档时间: |
|
| 查看次数: |
23831 次 |
| 最近记录: |