当前位置:首页 » 安卓系统 » 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符。

热点内容
linux存放文件 发布:2025-03-06 11:24:47 浏览:444
nfslinux挂载 发布:2025-03-06 11:19:42 浏览:231
安卓动态壁纸怎么提取 发布:2025-03-06 11:07:26 浏览:111
有锁安卓手机有什么坏处 发布:2025-03-06 11:00:20 浏览:575
dvwa上传 发布:2025-03-06 10:46:58 浏览:699
新款荣放低配有哪些新配置 发布:2025-03-06 10:41:29 浏览:791
如何给文件上加密 发布:2025-03-06 10:33:09 浏览:371
python类super 发布:2025-03-06 10:32:16 浏览:74
编程代码构成 发布:2025-03-06 10:23:58 浏览:955
如何看一台电视配置 发布:2025-03-06 10:18:08 浏览:253