Android API based TABS3 to implement Tabhost effect example _android

Source: Internet
Author: User

This article describes the Android API based TABS3 to achieve the tabhost effect. Share to everyone for your reference, specific as follows:

Two days ago, the teacher let himself write a video player client, this is his lectures on a small demo, by looking at the TABS3 of the Android API to achieve the tabhost effect of imitation cool video client. My API path is the TABS3 under D:\android\sdk\samples\android-17\ApiDemos\src\com\example\android\apis\view, and here is the implementation effect:

Nonsense not much said, directly on the code:

Mainactivity.java

Package com.example.video;
Import Android.os.Bundle; Import Android.
R.layout;
Import android.app.Activity;
Import android.app.TabActivity;
Import android.content.Intent;
Import Android.view.LayoutInflater;
Import Android.view.Menu;
Import Android.widget.TabHost;
  public class Mainactivity extends tabactivity {public tabhost tabhost;
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Gets the object tabhost = Gettabhost (); Tabhost.addtab (Tabhost.newtabspec ("Myself"). Setindicator ("Personal Center"). SetContent (New Intent (This, myselfactiv
    Ity.class))); Tabhost.addtab (Tabhost.newtabspec ("Myindex"). Setindicator ("Youku Home"). SetContent (New Intent (This, myindexact
    Ivity.class))); Tabhost.addtab (Tabhost.newtabspec ("Mycenter"). Setindicator ("Channel Center"). SetContent (New Intent (This, Mycentera
    Ctivity.class))); Specifies that the current tab//is Tabhost.setcurrenttab (0) with index-specified index starting from 0;
   Start from zero//Activate by identityTabhost.setcurrenttabbytag ("XXX1");  @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action Bar
    If it is present.
    Getmenuinflater (). Inflate (R.menu.main, menu);
  return true;

 }
}

Mycenteractivity.java

Package com.example.video;
Import android.app.Activity;
Import Android.os.Bundle;
public class Mycenteractivity extends activity{
  @Override
  protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (R.layout.activity_mycenter);
  }


Myindexactivity.java

Package com.example.video;
Import android.app.Activity;
Import Android.os.Bundle;
public class Myindexactivity extends activity{
  @Override
  protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (R.layout.activity_myindex);
  }


Myselfactivity.java

Package com.example.video;
Import android.app.Activity;
Import Android.os.Bundle;
public class Myselfactivity extends activity{
  @Override
  protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.activity_myself);
  }


The following is a layout file:

Activity_mycenter.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
  xmlns:tools= "http:// Schemas.android.com/tools "
  android:layout_width=" match_parent "
  android:layout_height=" Match_parent "
  android:paddingbottom= "@dimen/activity_vertical_margin"
  android:paddingleft= "@dimen/activity_ Horizontal_margin "
  android:paddingright=" @dimen/activity_horizontal_margin "
  android:paddingtop=" @dimen /activity_vertical_margin "
  tools:context=". Mainactivity ">
  <textview
    android:layout_width=" wrap_content "
    android:layout_height=" Wrap_ Content "
    android:text= Center"/>
</RelativeLayout>

Activity_myindex.xml

<textview
  android:layout_width= "wrap_content"
  android:layout_height= "Wrap_content"
  android: text= "Youku Home"/>

Activity_myself.xml

<textview
    android:layout_width= "wrap_content"
    android:layout_height= "wrap_content"
    android:text = "Personal Home"/>

Of course, don't forget to configure the activity in the manifest file

<!--Configure activity Components-->
<activity android:name= "com.example.video.MyIndexActivity"/>
< Activity android:name= "com.example.video.MySelfActivity"/>
<activity android:name= " Com.example.video.MyCenterActivity "/>

I hope this article will help you with the Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.