MUM*_*ĞLU 3 android android-actionbar splitactionbar
我想创建一个Android应用程序,它有3个滑动选项卡面板,每个都有5个按钮(保存,新建,删除,退出..).
我创建了滑动选项卡面板.对于5个按钮,我添加了分割操作栏.但它可以像普通的分割操作栏一样工作.我的AndroidManifest.xml是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<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)
我哪里错了?
splitActionBar:只需添加android:uiOptions="splitActionBarWhenNarrow"到您的activity标签中就可以了AndroidManifest.xml...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
Run Code Online (Sandbox Code Playgroud)
注意:它仅适用于屏幕宽度为的手机设备
400dp.
如果你想为所有设备设置它,请Creating custom bottom toolbar在这里检查我的答案(找到一个开头的帖子):
创建自定义底部工具栏
我已经创建了一个简单的应用程序,它应该向您展示如何开始
![]()
创建自定义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">确保设备键盘不会隐藏我的自定义底部工具栏.
如果您有任何疑问,请随意提问.
希望它有所帮助
| 归档时间: |
|
| 查看次数: |
2329 次 |
| 最近记录: |