導航:首頁 > 操作系統 > androidtab選項卡

androidtab選項卡

發布時間:2022-12-17 23:21:23

『壹』 android中想實現多個選項卡的切換,該如何實

Android中使用TabHost和TabWidget來實現選項卡功能。TabHost必須是布局的根節點,它包含兩個子節點:
TabWidget,顯示選項卡;
FrameLayout,顯示標簽內容。

實現選項卡功能有兩種方法,一種是將多個View放在同一個Activity中,然後使用使用標簽來進行切換。另一種是直接使用標簽切換不同的Activity。
後一種方法更為常用一些。
1. 創建一個工程,名字可以叫HelloTabWidget。
2. 創建多個不同的Activity,用來表示各個標簽頁中的不同內容。
3. 為標簽設計不同的icon。每個標簽應該有兩個icon,一個表示選中,一個未選中。將圖片放在 res/drawable/文件夾下。然後創建一個相應的
StateListDrawable,用來實現在選中和未選中直接自動的切換。

『貳』 android tabwidget 選項卡上的文字大小怎麼設置 圖中 用戶登陸和設備激活 的字體大小怎麼設置

使用 android:textSize屬性
<Button
android:layout_width="70dp" //設置按鈕的寬度
android:layout_height="50dp"
android:text="用戶登錄"
android:textSize="20dp「 //設置按鈕字體的大小
/>
有問題請繼續追問

『叄』 android中tab選項卡怎麼做

第一步
res/values/strings.xml

[xhtml] view plain
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MyTabActivity!</string>
<string name="app_name">選項卡Demo</string>
<string name="andy">Andy Rubin--<a href="http://lib.csdn.net/base/15" class='replace_word' title="undefined" target='_blank' style='color:#df3434; font-weight:bold;'>Android</a>的創造者</string>
<string name="bill">Bill Joy--java的創造者</string>
<string name="torvalds">Linus Torvalds --Linux之父</string>
</resources>

第二步
res/layout/tab_layout.xml

[xhtml] view plain
<?xml version="1.0" encoding="utf-8"?>
<!--
FrameLayout:一個FrameLayout對象好比一塊在屏幕上提前預定好的空白區域,
然後可以填充一些元素到里邊,比方說一張圖片等。
需要注意的是所有元素都被放置在FrameLayout區域的左上的區域,
而且無法為這些元素指定一個確切的位置。如果有多個元素,則後邊的會重疊在前一個元素上。

android:gravity用於設置View組件的對齊方式
(另外,android:layout_gravity用於設置Container組件的對齊方式)
center_horizontal 不改變控制項大小,對其到容器橫向中間位置(也就是在豎直方向的中間)

android:scaleType="fitXY" 把圖片不按比例來擴大或者縮小顯示
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/linearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView01"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/andy"/>
<TextView
android:id="@+id/testView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/andy"
/>
</LinearLayout>

<LinearLayout android:id="@+id/linearLayout2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView02"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bill"/>
<TextView
android:id="@+id/testView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/bill"
/>
</LinearLayout>

<LinearLayout android:id="@+id/linearLayout3"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView03"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/torvalds"/>
<TextView
android:id="@+id/testView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="@string/torvalds"
/>
</LinearLayout>
</FrameLayout>

第三步
src/com/myandroid/tab/MyTabActivity.java

[java] view plain
package com.myandroid.tab;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;

public class MyTabActivity extends TabActivity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = this.getTabHost();
/*
* LayoutInflater的作用類似於 findViewById(),
* 不同點是LayoutInflater是用來找layout文件夾下的xml布局文件,並且實例化
* 註:findViewById()只是找控制項之類(如Button和EditView)
*
* LayoutInflater.from(this)獲得context實例
* 也就是相當於this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
* LAYOUT_INFLATER_SERVICE 取得xml里定義的view
*-----------------------------------------------------------------------
* getSystemService:
* 根據傳入的NAME來取得對應的Object,然後轉換成相應的服務對象
* android的後台運行在很多service,
* 它們在系統啟動時被SystemServer開啟,支持系統的正常工作,
* 比如MountService監聽是否有SD卡安裝及移除,ClipboardService提供剪切板功能,
* 應用程序可以通過系統提供的Manager介面來訪問這些Service提供的數據
*-----------------------------------------------------------------------
*
* inflate是把xml表述的layout轉化為View
* tabHost.getTabContentView() 獲得Tab標簽頁的FrameLayout
* true表示將inflate綁定到根布局元素上
*/
LayoutInflater.from(this)
.inflate(R.layout.tab_layout,
tabHost.getTabContentView(), true);

/*
* tabHost.newTabSpec("Tab1") 創建TabHost.TabSpec,
* TabSpec即是選項卡的指示符,對於TabSpec可以設置一個標題或者設置一個標題和圖標
* setIndicator 是為選項卡指示符指定一個標簽和圖標
* setContent 為選項卡的內容指定視圖的ID
*/
tabHost.addTab(
tabHost.newTabSpec("Tab1")
.setIndicator("Tab1", getResources().getDrawable(R.drawable.png1)
).setContent(R.id.linearLayout1)
);
tabHost.addTab(
tabHost.newTabSpec("Tab2")
.setIndicator("Tab2", getResources().getDrawable(R.drawable.png2)
).setContent(R.id.linearLayout2)
);
tabHost.addTab(
tabHost.newTabSpec("Tab3")
.setIndicator("Tab3", getResources().getDrawable(R.drawable.png3)
).setContent(R.id.linearLayout3)
);
}

}

第四步
AndroidManifest.xml

[xhtml] view plain
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myandroid.tab"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyTabActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>

附上出處鏈接:http://blog.csdn.net/jamesliulyc/article/details/6324432

『肆』 android中的tabHost怎樣在點擊一個選項卡後跳轉到一個activity,點擊另一個選項卡跳轉到另一個activity

一個Tab頁,中間有個按鈕可以跳轉到另一個Activity

我的TabHost是
intent = new Intent(this,Activity01.class);//新建一個Intent用作Tab1顯示的內容
spec = tabHost.newTabSpec("tab1")//新建一個 Tab
.setIndicator("tab1")//設置名稱以及圖標
.setContent(intent);//設置顯示的intent,這里的參數也可以是R.id.xxx
tabHost.addTab(spec);//添加進tabHost
這個方式添加進來的,載入Acitivity01

『伍』 android 怎麼設置TabHost默認顯示的選項卡為選中狀態

int currentTab = tabhost.getCurrentTab();
if(currentTab == 默認選項卡){
//設置背景顏色區別其他tab的顏色就搞定

}

『陸』 Android選項卡,一直報「TabWidget with id "android:id/tabs".」這個錯,試了好幾個API都不行

在布局中用TabHost,必須有一個TabWidget的子控制項,並且控制項id一定要是android預先定義的「android:id/tabs」,你只寫一個TabHost當然會報這個錯

『柒』 android 怎麼設置TabHost默認顯示的選項卡為選中狀態

給TAB卡做個布局,在布局裡面把TextView設置成居中 給個事例給你看下 TabHost.TabSpec localTabSpec1 = this.tabHost.newTabSpec("1"); //R.Layout.tab_indicator 就是TAB選項卡的布局 View localView = getLayoutInflater().inflate(R.layout.tab_indicator, null); ImageView localImageView = (ImageView) localView.findViewById(R.id.icon); localImageView.setImageResource(R.drawable.menu_ranking); TabHost.TabSpec localTabSpec2 = localTabSpec1.setIndicator(localView); Intent localIntent = new Intent(this, RankActivity.class); localTabSpec2.setContent(localIntent); this.tabHost.addTab(localTabSpec1);

『捌』 android 如何設置TabHost默認顯示的選項卡為選中狀態

tabHost.setCurrentTab(1);

『玖』 關於Android界面組件的基本用法

1.文本框(TextView)和編輯框(EditText)
文本框(TextView)不允許用戶編輯文本內容,而編輯框(EditText)允許用戶編輯文本內容

2.按鈕(Button)和圖片按鈕(ImageButton)
Button顯示文字,ImageButton顯示圖片。
為ImageButton指定android:text屬性沒用,不會顯示文字
可以指定android:background為按鈕增加背景圖片,但這圖片是固定的
可以指定android:src為圖片按鈕增加圖片屬性
其實,src才是設置圖標,而background只是設置背景。
如果控制項的大小是100 100 圖片資源是80 80的話,那麼用src,圖片就會居中顯示,如果使用background那麼圖片就會被拉伸充滿控制項。
重要的是,background是底層的圖片資源,src是覆蓋在background上面的資源,他們可以疊加使用,實現選中的效果。

3.單選按鈕(RadioButton)和復選框(CheckBox)
多了一個android:checked屬性,用於指定初始時是否被選中

4.計時器組件Chronometer用法
紅色字體表示常用的方法

5.圖像視圖(ImageView)
它支持屬性android:scaleType setScaleType(ImageView.ScaleType)

matrix(ImageView.ScaleType.MATRIX):使用matrix方式進行
fixXY(ImageView.ScaleType.FIX_XY):對圖片橫向縱向獨立縮放,會改變縱橫比
fitStart(ImageView.ScaleType.FIT_START):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在左上角
fitCenter(ImageView.ScaleType.FIT_CENTER):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在中央
fitEnd(ImageView.ScaleType.FIT_END):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在右下角
center(ImageView.ScaleType.CENTER):放中間,不縮放
centerCrop(ImageView.ScaleType.CENTER_CROP):保持縱橫比,使圖片能完全覆蓋ImageView
centerInside(ImageView.ScaleType.CENTER_INSIDE):保持縱橫比,使ImageView能完全顯示圖片
6.spinner的功能和用法
如果可以確定spinner裡面的列表項,那麼直接在/res/layout/main.xml裡面指定

然後在/res/value/string.xml裡面指定

如果不確定裡面的列表項,那麼必須要提供一個Adapter,這個Adapter負責決定Spinner列表每項的內容

7.日期、時間選擇器(DatePicker和TimePicker)

8.自動完成文本框(AutoCompleteTextView)
比普通文本框多了一個功能:當用戶輸入一定字元後,自動完成文本框會顯示一個下拉菜單,供用戶從中選擇,當用戶選擇某個菜單後,組件會按用戶選擇自動填寫該文本框
使用該組件很簡單,只要為它設置一個Adapter,該Adapter封裝了AutoCompleteTextView預設的提示文本

9.進度條(ProgressBar)
通過style屬性可以為ProgressBar指定風格。該屬性可以有如下的屬性值:

1.@android:style/Widget.ProgressBar.Horizontal 水平進度條
2.@android:style/Widget.ProgressBar.Inverse 不斷跳躍、旋轉畫面的進度條
3.@android:style/Widget.ProgressBar.Large 大進度條
4.@android:style/Widget.ProgressBar.Large.Inverse不斷跳躍、旋轉畫面的大進度條
5.@android:style/Widget.ProgressBar.Small 小進度條
6.@android:style/Widget.ProgressBar.Small.Inverse不斷跳躍、旋轉畫面的小進度條
ProgressBar提供如下方法來操作進度

1.setProgress(int) 設置進度的完成百分比
2.incrementProgressBy(int) 設置進度條的增加或減少。參數為正增加,參數為負減少

10.選項卡(TabHost)
TabHost僅僅只是一個簡單的容器,它提供如下方法

1.newTabSpec(String tag) 創建選項卡
2.addTab(TabHost.TabSpec tabSpec) 添加選項卡
使用TabHost的一般步驟為:

• A. 在界面中定義TabHost組件,並為該組件定義該選項卡的內容
• B. Activity應該繼承TabActivity
• C. 調用TabActivity的getTabHost()來獲取TabHost對象
• D. 通過TabHost對象的方法來創建選項卡、添加選項卡
選項卡主要由TabHost、TabWidget、FrameLayout3個組件組成,三者缺一不可,想像一下選項卡的特點,多個卡重疊在一起,所以用FrameLayout即幀布局是必要的。另外需要注意的是TabHost、TabWidget、FrameLayout三個組件的android:id必須使用系統默認的名稱,而不能自己隨意定義,否則會出錯。

11.圖像切換器(ImageSwitcher)

12.網格視圖(GridView)
使用GridView一般指定numColumn大於1,否則取默認值為1.那麼GridView就變成了ListView
屬性android:stretchMode支持如下屬性

1.none 不拉伸
2.spacingWidth 僅拉伸元素之間的間距
3.spacingWidthUniform 表格、元素之間的間距一起拉伸
4.columnWidth 僅拉伸表格
13.畫廊視圖(Gallery)(現在已經被棄用了,不過還是列出來吧)
Gallery用法很簡單——為它提供一個內容Adapter,該Adapter的getView方法所返回的View可作為Gallery的列表項。可以通過OnItemSelectedListener監聽選擇項的改變

14.列表試圖(ListView和ListActivity)
1.創建ListView由兩種方式:

2.直接使用ListView進行創建
讓Activity繼承ListActivity(繼承了ListActivity的類無需調用setContentView()來顯示頁面,可以直接設置適配器)
一旦獲得ListView後,就要創建顯示的列表項了。需要藉助內容Adapter,內容Adapter負責提供需要顯示的列表項

創建ArrayAdapter時必須指定一個textViewResourceId,該參數決定每個列表項的外觀

1.simple_list_item_1 每個列表項是普通的TextView
2.simple_list_item_2 每個列表項是普通的TextView(字體略大)
3.simple_list_item_checked 每個列表項是已勾選的列表項
4.simple_list_item_multiple_choice 每個列表項是帶多選框的文本
5.simple_list_item_single_choice 每個列表項是帶多單選按鈕的文本
15.使用AlertDialog
1.創建AlertDialog.Builder對象,該對象是AlertDialog的創建器
2.調用AlertDialog.Builder方法為對話框設置圖標、標題等
3.調用AlertDialog.Builder的create()方法創建AlertDialog對話框
4.調用AlertDialog的show()方法顯示對話框

16.使用Toast顯示提示框
步驟如下:

• 調用Toast構造器或makeText方法創建Toast對象
• 調用Toast方法來設置該消息的對齊方式等
• 調用Toast的show()方法顯示出來
• Toast toast = Toast.makeText(ToastTest.this, "信息", Toast.LENGTH_LONG).show();

17.Notification(一般顯示網路狀態、電池狀態、時間等)
使用Notification發送Notification步驟:

• 調用getSystemService(NOTIFICATION_SERVICE)方法獲取系統的Notification Manager服務
• 通過構造器創建一個Notification對象
• 為Notification設置屬性
• 通過Notification Manager發送Notification

『拾』 android tab選項卡 切換的時候特別卡

可能是你模擬器或者手機的問題,也可能是代碼的問題導致的,可以嘗試換一個性能好一點的手機試試,推薦你一款神器:genymotion(超快的android模擬器)

閱讀全文

與androidtab選項卡相關的資料

熱點內容
蘋果如何創建伺服器錯誤 瀏覽:495
軟考初級程序員大題分值 瀏覽:473
js壓縮視頻文件 瀏覽:578
linux如何通過命令創建文件 瀏覽:989
應用加密app還能訪問應用嘛 瀏覽:433
安卓怎麼用支付寶交違章罰款 瀏覽:665
php面向對象的程序設計 瀏覽:504
數據挖掘演算法書籍推薦 瀏覽:894
投訴聯通用什麼app 瀏覽:150
web伺服器變更ip地址 瀏覽:954
java正則表達式驗證郵箱 瀏覽:360
成熟商務男裝下載什麼軟體app 瀏覽:609
加密2h代表長度是多少厘米 瀏覽:23
拍賣程序員 瀏覽:101
電腦的圖片放在哪個文件夾 瀏覽:276
unsignedintjava 瀏覽:217
編譯器下載地址 瀏覽:43
什麼是面對對象編程 瀏覽:708
b站伺服器什麼時候恢復 瀏覽:721
6p相當於安卓機什麼水準 瀏覽:499