Create a tab layout for Android (note)
You can use TabHost to create a label-based layout and switch between different labels to display different background images. The effect is as follows:
11000000006 image resources (gray.png, white.png, gray2.png, white2.png, gray3.png, and white3.png indicate the default label status and the status after the tag is pressed.
2. Create a New XML file in the drawable folder, such as picture. xml, picture2.xml, and picture3.xml. Fill in the following code respectively.
Picture. xml
Picture2.xml
Picture3.xml
3. Add the control in activity_main.xml and call it in MainActivity. java.
Activity_main.xml
<framelayout android:id="@+id/container" android:layout_height="match_parent" android:layout_width="match_parent" tools:context="com.example.test2.MainActivity" tools:ignore="MergeRootFrame" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
</framelayout>
MainActivity. xml
Package com. example. test3; import android. app. activity; import android. app. actionBar; import android. app. fragment; import android. app. tabActivity; import android. content. intent; import android. content. res. resources; import android. graphics. drawable. drawable; import android. OS. bundle; import android. view. layoutInflater; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. viewGroup; import android. widget. tabHost; import android. widget. tabHost. tabSpec; import android. OS. build; public class MainActivity extends TabActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); TabHost tabHost = getTabHost (); LayoutInflater. from (this ). inflate (R. layout. activity_main, // load the page tabHost. getTabContentView (), true); tabHost. addTab (tabHost. newTabSpec (tab1 ). setIndicator (tab1, getResources (). getDrawable (R. drawable. picture )). setContent (R. id. view1); tabHost. addTab (tabHost. newTabSpec (tab2 ). setIndicator (tab2, getResources (). getDrawable (R. drawable. picture2 )). setContent (R. id. view2); tabHost. addTab (tabHost. newTabSpec (tab3 ). setIndicator (tab3, getResources (). getDrawable (R. drawable. picture3 )). setContent (R. id. view3); tabHost. setCurrentTab (1 );}}
4. After the test, if the icon is not displayed, the following changes are made in AndroidManifest. xml to see the icon.