Android基于API的Tabs3實(shí)現(xiàn)仿優(yōu)酷t(yī)abhost效果實(shí)例
本文實(shí)例講述了Android基于API的Tabs3實(shí)現(xiàn)仿優(yōu)酷t(yī)abhost效果。分享給大家供大家參考,具體如下:
前兩天老師就讓自己寫個(gè)視頻播放器客戶端,這個(gè)是他上課講的一個(gè)小小demo,通過查看安卓API的tabs3,實(shí)現(xiàn)仿優(yōu)酷視頻客戶端的tabhost效果。我的API路徑是D:\android\sdk\samples\android-17\ApiDemos\src\com\example\android\apis\view下的Tabs3,下面是實(shí)現(xiàn)效果:

廢話不多說了,直接上碼:
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);
//獲取對(duì)象
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("myself")
.setIndicator("個(gè)人中心")
.setContent(new Intent(this, MySelfActivity.class)));
tabHost.addTab(tabHost.newTabSpec("myindex")
.setIndicator("優(yōu)酷首頁(yè)")
.setContent(new Intent(this, MyIndexActivity.class)));
tabHost.addTab(tabHost.newTabSpec("mycenter")
.setIndicator("頻道中心")
.setContent(new Intent(this, MyCenterActivity.class)));
//指定的當(dāng)前的tab
//通過索引指定 索引從0開始
tabHost.setCurrentTab(0); //從零開始
//通過標(biāo)識(shí)來激活
// tabHost.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);
}
}
下面是布局文件:
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="優(yōu)酷中心" />
</RelativeLayout>
activity_myindex.xml
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="優(yōu)酷首頁(yè)" />
activity_myself.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="個(gè)人首頁(yè)" />
當(dāng)然別忘了在清單文件中配置activity
<!-- 配置activity組件 --> <activity android:name="com.example.video.MyIndexActivity"/> <activity android:name="com.example.video.MySelfActivity"/> <activity android:name="com.example.video.MyCenterActivity"/>
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- android 微信 sdk api調(diào)用不成功解決方案
- android monkey自動(dòng)化測(cè)試改為java調(diào)用monkeyrunner Api
- Android 高版本API方法在低版本系統(tǒng)上的兼容性處理
- Android 調(diào)用百度地圖API示例
- android開發(fā)教程之獲取使用當(dāng)前api的應(yīng)用程序名稱
- android通過google api獲取天氣信息示例
- android通過Location API顯示地址信息的實(shí)現(xiàn)方法
- Android通過原生APi獲取所在位置的經(jīng)緯度
- Android提高之藍(lán)牙隱藏API探秘
- Android指紋識(shí)別API初試
- Android開發(fā)學(xué)習(xí)筆記之通過API接口將LaTex數(shù)學(xué)函數(shù)表達(dá)式轉(zhuǎn)化為圖片形式
- Android 支付寶支付、微信支付、銀聯(lián)支付 整合第三方支付接入方法(后臺(tái)訂單支付API設(shè)計(jì))
- Android4.4 WebAPI實(shí)現(xiàn)拍照上傳功能
- 使用android隱藏api實(shí)現(xiàn)亮度調(diào)節(jié)的方法
- Android API開發(fā)之SMS短信服務(wù)處理和獲取聯(lián)系人的方法
- Android 用 camera2 API 自定義相機(jī)
- Android 多媒體播放API簡(jiǎn)單實(shí)例
- 最新Android版本、代號(hào)、對(duì)應(yīng)API/NDK級(jí)別、發(fā)布時(shí)間及市場(chǎng)份額
相關(guān)文章
Android中系統(tǒng)默認(rèn)輸入法設(shè)置的方法(輸入法的顯示和隱藏)
這篇文章主要介紹了Android中系統(tǒng)默認(rèn)輸入法設(shè)置的方法(輸入法的顯示和隱藏)的相關(guān)資料,需要的朋友可以參考下2016-01-01
Android應(yīng)用開發(fā)中RecyclerView組件使用入門教程
這篇文章主要介紹了Android應(yīng)用開發(fā)中RecyclerView組件使用的入門教程,RecyclerView主要針對(duì)安卓5.0以上的material design開發(fā)提供支持,需要的朋友可以參考下2016-02-02
Android xml實(shí)現(xiàn)animation的4種動(dòng)畫效果實(shí)例代碼
在Android應(yīng)用程序,使用動(dòng)畫效果,能帶給用戶更好的感覺,做動(dòng)畫可以通過XML或Android代碼來實(shí)現(xiàn)。本文給大家介紹Android xml實(shí)現(xiàn)animation的4種動(dòng)畫效果實(shí)例代碼,一起看看吧2016-05-05
Android使用手勢(shì)實(shí)現(xiàn)翻頁(yè)效果
Kotlin學(xué)習(xí)教程之函數(shù)的默認(rèn)參數(shù)
Android中pendingIntent與Intent的深入分析

