![](/img/trans.png)
[英]Modifying Holo Theme (ActionBar Sherlock) to put tabs above Action Bar?
[英]ActionBar Sherlock , action bar tabs and fragments
我想為手機和平板電腦創建一個應用程序。我正在使用actiobBar sherlock庫。 我有一個MainActivity擴展了SherlockFragmentActivity。 MainActivity有一個僅包含選項卡的操作欄。 現在,我想為每個選項卡關聯一個片段,並且該片段應具有兩個片段(列表片段和詳細片段)。 請建議我該怎么做。
有幾種方法,我只解釋一下。
您可以使用任何導航,ViewPager,TabAdapter ...這個想法是添加一層片段 。
例如,您的TabAdapter帶有視圖尋呼機:
private ViewPager _viewPager;
private TabsAdapter _tabsAdapter;
_tabsAdapter = new TabsAdapter(this, _viewPager);
_tabsAdapter.addTab(bar.newTab().setCustomView(getTabIndicator(getString(R.string.tle_tab_home), R.drawable.ic_menu_home)), FragmentAccueil.class, null);
_tabsAdapter.addTab(bar.newTab().setCustomView(getTabIndicator(getString(R.string.tle_tab_directory), R.drawable.tab_list_icon)), ContainerFragmentAnnuaire.class, null);
ContainerFragmentAnnuaire是包含片段的布局
例如,對於手機,您將創建此布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.example.android.ContainerFragmentAnnuaire"
android:id="@+id/list_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
對於平板電腦,您將創建一個
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frags">
<fragment class="com.example.android.ContainerFragmentAnnuaire"
android:id="@+id/list_frag"
android:layout_width="@dimen/titles_size"
android:layout_height="match_parent"/>
<fragment class="com.example.android.ContainerFragmentDetail"
android:id="@+id/details_frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
只需將布局添加到好文件夾中
手機的 res / layout / layout.xml
平板電腦的 res / layout-large / layout.xml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.