[英]Action Bar Tabs at the bottom?
I'm trying to place the action bar tabs at the bottom of my app, but I need some help with it (if it's even possible). 我正在尝试将操作栏选项卡放在我的应用程序的底部,但我需要一些帮助(如果它甚至可能)。
The code: 代码:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabA = actionBar.newTab().setText("Games");
ActionBar.Tab tabB = actionBar.newTab().setText("Apps");
ActionBar.Tab tabC = actionBar.newTab().setText("Themes");
tabA.setTabListener(new ActionBarTabListener());
tabB.setTabListener(new ActionBarTabListener());
tabC.setTabListener(new ActionBarTabListener());
actionBar.addTab(tabA);
actionBar.addTab(tabB);
actionBar.addTab(tabC);
它有点违反Android指南,将标签放在底部,但是分割操作栏应该能够完成你想要做的事情。
There is another way to this but you have to use FrgamentTabHost. 还有另一种方法,但你必须使用FrgamentTabHost。
Here is the code. 这是代码。 layout/activity_main.xml 布局/ activity_main.xml中
enter <android.support.v4.app.FragmentTabHost
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</LinearLayout>
You have to place TabWidget below the FrameLayout. 你必须将TabWidget放在FrameLayout下面。
layout/fragment_layout.xml 布局/ fragment_layout.xml
enter code here<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#eaecee">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="@string/hello_world"
android:textAppearance="?android:attr/textAppearanceMedium" />
MainActivity.java MainActivity.java
import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTabHost; public class MainActivity extends FragmentActivity { private FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null), FragmentTab.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator("Tab 2", null), FragmentTab.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab3").setIndicator("Tab 3", null), FragmentTab.class, null); } }
FragmentTab.java FragmentTab.java
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class FragmentTab extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_layout, container, false); TextView tv = (TextView) v.findViewById(R.id.text); tv.setText(this.getTag() + " Content"); return v; } }
I hope it would help you. 我希望它会对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.