是否可以在 android 中实现像 iOS 这样的底部标签栏功能?
Is it possible to implement bottom tab bar functionality like iOS in android?
在 iOS 中,底部标签栏功能非常基本。但是在 android 中,我无法实现这个功能。
我的想法如下。
标签栏包含 SMS、Call、Camera - 3 个标签栏图标。
每当点击此图标时,我想在我的 android 设备上 运行 发送短信、Phone 通话和安装摄像头。
但是这些应该和iOS tab View是一样的。 (应该不是全屏)
我已经找到了很长时间的解决方案,但我找不到正确的方法。
请帮我
谢谢
是的,底部可能有标签栏
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:divider="@drawable/bg_tab_seperator"
android:dividerPadding="0dp" />
</RelativeLayout>
</TabHost>
把这个放在 XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/home_background_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
app:tabPadding="10dp"
android:minHeight="100dp"
app:tabGravity="fill"
app:tabIndicatorColor="@color/app_primary_color"
app:tabMode="fixed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
这在代码中
try
{
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.getTabAt(0).setIcon(R.drawable.tab_icon1);
tabLayout.getTabAt(1).setIcon(R.drawable.tab_icon2);
tabLayout.getTabAt(2).setIcon(R.drawable.tab_icon3);
tabLayout.getTabAt(3).setIcon(R.drawable.tab_icon4);
}
catch (Exception e)
{
Log.e("TabLayout Creation Error",e.getMessage());
}
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch(tabLayout.getSelectedTabPosition())
{
case 0:
break;
case 1:
//Do the stuff
break;
case 2:
//Do the stuff
break;
case 3:
//Do the stuff
break;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
我已经在我的一个应用程序中实现了你所说的..很快就会 post xm
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_above="@+id/app_bar"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/background"
>
<com.****.****.ui.custom.IconTextTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_tab_layout_height"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
我的 <com.****.****.ui.custom.IconTextTabLayout
只是一个 class 扩展 TabLayout
你可以使用默认的小部件。
在 iOS 中,底部标签栏功能非常基本。但是在 android 中,我无法实现这个功能。 我的想法如下。 标签栏包含 SMS、Call、Camera - 3 个标签栏图标。 每当点击此图标时,我想在我的 android 设备上 运行 发送短信、Phone 通话和安装摄像头。 但是这些应该和iOS tab View是一样的。 (应该不是全屏) 我已经找到了很长时间的解决方案,但我找不到正确的方法。 请帮我 谢谢
是的,底部可能有标签栏 试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:divider="@drawable/bg_tab_seperator"
android:dividerPadding="0dp" />
</RelativeLayout>
</TabHost>
把这个放在 XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/home_background_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
app:tabPadding="10dp"
android:minHeight="100dp"
app:tabGravity="fill"
app:tabIndicatorColor="@color/app_primary_color"
app:tabMode="fixed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
这在代码中
try
{
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.getTabAt(0).setIcon(R.drawable.tab_icon1);
tabLayout.getTabAt(1).setIcon(R.drawable.tab_icon2);
tabLayout.getTabAt(2).setIcon(R.drawable.tab_icon3);
tabLayout.getTabAt(3).setIcon(R.drawable.tab_icon4);
}
catch (Exception e)
{
Log.e("TabLayout Creation Error",e.getMessage());
}
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch(tabLayout.getSelectedTabPosition())
{
case 0:
break;
case 1:
//Do the stuff
break;
case 2:
//Do the stuff
break;
case 3:
//Do the stuff
break;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
我已经在我的一个应用程序中实现了你所说的..很快就会 post xm
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_above="@+id/app_bar"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/background"
>
<com.****.****.ui.custom.IconTextTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_tab_layout_height"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
我的 <com.****.****.ui.custom.IconTextTabLayout
只是一个 class 扩展 TabLayout
你可以使用默认的小部件。