當前位置:首頁 » 安卓系統 » tabandroid

tabandroid

發布時間: 2022-10-31 06:23:57

㈠ Android應用的tab導航是放在屏幕頂部好還是底部好

Android Design 中說的是放在頂部,而且 Effective 的 Navigation 方式是再配上 ViewPager .因為現在手機屏幕越做越大,單純把 Tab 放在頂上,幾個 Fragment 之間還不好劃著切換會很蛋疼,例子見三星的大部分原廠應用(其實三星做系統也就基本上改UI,深層次改動沒有,所以三星的系統也是'各大廠商修改的 Android 里最趨於穩定的)。而Tab放在下面的好處不必多說,可以讓用戶單手就可以按到並實現切換,例如魅族的 SmartBar,開發者只要反射一個介面方法就可以把Tab放到下面來,還是蠻方便的。

㈡ android tablayout怎麼使用代碼切換tab

android tablayout怎麼使用代碼切換tab
重新設置點擊事件
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);

for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
tab.setCustomView(pagerAdapter.getTabView(i));
if (tab.getCustomView() != null) {
View tabView = (View) tab.getCustomView().getParent();
tabView.setTag(i);
tabView.setOnClickListener(mTabOnClickListener);
}
}
}
viewPager.setCurrentItem(1);

處理點擊事件
private View.OnClickListener mTabOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = (int) view.getTag();
if (pos == 0) {
Toast.makeText(BottomTabActivity.this, "您還沒有登錄", Toast.LENGTH_SHORT).show();
//TODO 跳轉到登錄界面
} else {
TabLayout.Tab tab = tabLayout.getTabAt(pos);
if (tab != null) {
tab.select();
}
}
}
};

㈢ 如何改變Android tab 的高度和字體大小

可以通過一下代碼實現改變Android tab 的高度和字體大小:
nt count = tabWidget.getChildCount();
for (int i = 0; i < count; i++) {
View view = tabWidget.getChildTabViewAt(i);
view.getLayoutParams().height = 80; //tabWidget.getChildAt(i)
final TextView tv = (TextView) view.findViewById(android.R.id.title);
tv.setTextSize(28);
tv.setTextColor(this.getResources().getColorStateList(
android.R.color.white));
}

㈣ 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

㈤ 如何創建tab android

您好,很高興為您解答:
在創建Tab之前,先把Tab的結構搞清楚。它的結構是這樣的:

最外層是一個Tabhost,Tabhost里裝了些選項卡(TabSpec),每個選項卡有自己的指示符(Indicator,就是頂部可點的那個區塊)和內容(Content,下半部分展示內容的區塊)。

現在,要做的事情就很清楚了:

1、創建Tabhost

2、創建TabSpec並給TabSpec賦值

3、把TabSpec添加到Tabhost中
如果我的回答沒能幫助您,請繼續追問。

安卓手機上如何打出 tab鍵

在網路輸入法里下載一個叫「apple風格點選布局」的皮膚,這個皮膚最上面有一排數字鍵,數字「8」的下面就是tab符,在數字8下面往下滑就能輸入tab符。

熱點內容
安卓如何設置每天定時發送消息 發布:2025-03-06 03:20:56 瀏覽:597
視頻免費上傳網站 發布:2025-03-06 03:19:17 瀏覽:567
運用運演算法 發布:2025-03-06 03:09:20 瀏覽:996
oomandroid 發布:2025-03-06 03:07:46 瀏覽:948
創造與魔法人間驚鴻客腳本 發布:2025-03-06 03:06:48 瀏覽:33
插頭是什麼配置 發布:2025-03-06 02:58:05 瀏覽:410
ipad更新要密碼怎麼辦 發布:2025-03-06 02:57:23 瀏覽:873
量子鏈源碼 發布:2025-03-06 02:52:25 瀏覽:135
androidxmldom解析 發布:2025-03-06 02:52:19 瀏覽:84
火影存儲路徑 發布:2025-03-06 02:50:59 瀏覽:530