简体   繁体   中英

how to customize android tab widget

I tried to add tab widget for my application. when i clicked it, it displayed border for the selected tab.How can i remove it??

I want to remove this gray color border

在此处输入图片说明

This is the xml design for the tabs

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

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#160203" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                <EditText
                    android:id="@+id/editText1"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_above="@+id/imageView2"
                    android:layout_alignRight="@+id/imageView7"
                    android:layout_marginBottom="40dp"
                    android:background="#ffffff"
                    android:ems="10"
                    android:inputType="textPersonName" />
                </LinearLayout>



                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <EditText
                    android:id="@+id/editText1"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_above="@+id/imageView2"
                    android:layout_alignRight="@+id/imageView7"
                    android:layout_marginBottom="40dp"
                    android:background="#ffffff"
                    android:ems="10"
                    android:inputType="textPersonName" />


                    </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >


                     <EditText
                    android:id="@+id/editText1"
                    android:layout_width="200dp"
                    android:layout_height="40dp"
                    android:layout_above="@+id/imageView2"
                    android:layout_alignRight="@+id/imageView7"
                    android:layout_marginBottom="40dp"
                    android:background="#ffffff"
                    android:ems="10"
                    android:inputType="textPersonName" />
                </LinearLayout>

            </FrameLayout>
        </LinearLayout>
    </TabHost>

This is the Activity class

TabHost tabHost = getTabHost();


            TabSpec favourite = tabHost.newTabSpec("favourite");

            favourite.setIndicator("", getResources().getDrawable(R.drawable.favoritetwo));
            Intent photosIntent = new Intent(this, Favourite.class);
            favourite.setContent(photosIntent);


            TabSpec Offers = tabHost.newTabSpec("Offers");        
            Offers.setIndicator("", getResources().getDrawable(R.drawable.offertwo));
            Intent songsIntent = new Intent(this, Offers.class);
            Offers.setContent(songsIntent);


            TabSpec nearBy = tabHost.newTabSpec("nearBy");
            nearBy.setIndicator("", getResources().getDrawable(R.drawable.nearbytwo));
            Intent videosIntent = new Intent(this, Near_By.class);
            nearBy.setContent(videosIntent);


            tabHost.addTab(favourite); 
            tabHost.addTab(Offers); 
            tabHost.addTab(nearBy); 

Can anyone help me???

Instead of changing the Image, We need to use a state-list drawable? Then you'd just specify a different drawable for the tab when it is selected.

Example, ic_tab_tasks.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_tab_tasks_selected"
          android:state_selected="true" />
    <item android:drawable="@drawable/ic_tab_tasks_normal" />
</selector>

Then, when you're setting the tab indicator's drawable initially, just use the state-list drawable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM