Android - Tabs in bottom of screen

戏子无情 提交于 2019-12-12 07:13:35

问题


I have been looking for about a day for a way to get my android application have tabs in the bottom of the screen.

On the Android Developer website in the Styles and Themes section, they seem to have the exact example of what I am trying to do, however they did not find it necessary to provide a decent example of this:

All the tips/solutions I find on the web are failing. I always seem to get the following butt-ugly layout where the tabs are very misplaced in the top of the screen next to the application name :-(

Does anyone have a clue how to accomplish this ?

Thank you so much in advance for any tips !


回答1:


I think these examples will be useful to you: Android Bottom tab bar example AND THIS




回答2:


Here is the two link of github that has implemented tab at bottom.

https://github.com/AdilSoomro/Iphone-Tab-in-Android

https://github.com/AdilSoomro/Raised-Center-Tab-in-Android




回答3:


I use this layout for locate Tabs in bottom of screen:

?xml version="1.0" encoding="utf-8"?>
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>
        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:background="@drawable/bg_main_app_gradient"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:background="#EAE7E1"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
    </LinearLayout>
</TabHost>

examle of code: https://stackoverflow.com/a/23150258/2765497




回答4:


I think you have not search enough for your problem because you are searching using the wrong keyword.

What you are showing in 1st image at bottom of gmail app there are 4 menu and 5th overflow menu and upper at top action bar

You can place a menu at the bottom using a simple property in the manifest; one single line on main activity which showing action bar

android:uiOptions="splitActionBarWhenNarrow"

Like this :

<activity
    android:name="com.example.HomeActivity"
    android:screenOrientation="portrait"
        android:uiOptions="splitActionBarWhenNarrow"
    android:theme="@style/Theme.Sherlock.Light" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>



回答5:


Google does not recommend to have Tabs at the bottom.

See the following official design pattern guide from Android,
And look for the section "Don't use bottom tab bars"

http://developer.android.com/design/patterns/pure-android.html




回答6:


I wanted to post an update here. Bottom nav bars are now Android Canon. The main take-aways from this are:

1) Use bottom nav bars only for 3-5 icons. Any less, use tabs. Any more, use scrollable tabs (page down on that same link).

2) Avoid using a bottom nav bar and tabs together, and be sure the responsibilities of both are clearly separated if you do.

3) Bottom nav bars should be used for navigation not actions (use the ActionBar for those)




回答7:


With the introduction of Bottom navigation.

https://material.google.com/components/bottom-navigation.html

You can do this

https://stackoverflow.com/a/36033640/6207502




回答8:


Its very simple....

For simple tab bar we use

<?xml version="1.0" encoding="utf-8"?>
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

But in Bottom Tab bar we use

**

<?xml version="1.0" encoding="utf-8"?>
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_alignParentBottom="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </RelativeLayout>
</TabHost>**

The main thing is

 android:layout_alignParentBottom=”true”;



回答9:


I came across your question seeking to do the same thing, however according to androids development guidelines, you should not ever have a tab bar at the bottom, since this is an iOS feature...

Android Development Standards




回答10:


You seem to have the bottom bar a bit confused. That's not a tab bar. The bottom bar is for actions, not navigating screens. For example, in the screenshot of the Gmail app you posted above, the bottom bar allows the user to: Compose Email, Search, Tag, Refresh and More. Refer: http://developer.android.com/design/patterns/actionbar.html

Technically these buttons do navigate the user to other screens but, the tab bar is usually used to "switch" screens. For example viewing content by category.

Hmm, but in the latest version of the Gmail app they have these action buttons on top. Sigh...



来源:https://stackoverflow.com/questions/18944692/android-tabs-in-bottom-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!