0
我已經按照教程瞭解如何創建可以在使用片段之間滑動的選項卡,但現在由於完成了教程,我需要在選項卡上實現自定義設計。我可以這樣做嗎,因爲在教程中沒有解釋這一點。自定義選項卡設計與可滑動視圖
我已經按照教程瞭解如何創建可以在使用片段之間滑動的選項卡,但現在由於完成了教程,我需要在選項卡上實現自定義設計。我可以這樣做嗎,因爲在教程中沒有解釋這一點。自定義選項卡設計與可滑動視圖
創建自定義選項卡的佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" android:gravity="center" android:orientation="vertical">
<TextView android:id="@+id/tabsText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Title"
android:textSize="15dip" />
</LinearLayout>
自定義視圖的外觀和感覺
tabs_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/tab_bg_selector"
android:padding="10dip" android:gravity="center" android:orientation="vertical">
<TextView android:id="@+id/tabsText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Title"
android:textSize="15dip" android:textColor="@drawable/tab_text_selector" />
</LinearLayout>
同樣設置文本和背景selector.use它作爲您的新佈局
有關更多詳細信息,請參閱this。
創建drawble文件夾
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/videos_gray"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/videos_white" />
XML(TAB1)和使用,在Java文件
// Create an actionbar
ActionBar actionBar = getActionBar();
// Hide Actionbar Icon
actionBar.setDisplayShowHomeEnabled(false);
// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(false);
// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create first Tab
tab = actionBar.newTab().setTabListener(new FragmentTab1());
// Create your own custom icon
tab.setIcon(R.drawable.tab1);
actionBar.addTab(tab);
// Create Second Tab
tab = actionBar.newTab().setTabListener(new FragmentTab2());
// Set Tab Title
tab.setText("Tab2");
actionBar.addTab(tab);
// Create Third Tab
tab = actionBar.newTab().setTabListener(new FragmentTab3());
// Set Tab Title
tab.setText("Tab3");
actionBar.addTab(tab);