- 浏览: 64400 次
- 性别:
- 来自: 沈阳
文章分类
最新评论
// mTabHost定义在Activity的属性
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup();
LayoutInflater factory = null;
// 未开始
factory = LayoutInflater.from(this);
final View notStartview = factory.inflate(R.layout.tab,null);
TextView notStartTextView = (TextView)notStartview.findViewById(R.id.tabName);
notStartTextView.setText(getText(R.string.text_tab_notstart));
notStartTextView
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 进行中
factory = LayoutInflater.from(this);
final View playingView = factory.inflate(R.layout.tab,null);
TextView playingTextView = (TextView)playingView.findViewById(R.id.tabName);
playingTextView.setText(getText(R.string.text_tab_playing));
playingTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));
// 已完场
factory = LayoutInflater.from(this);
final View finishView = factory.inflate(R.layout.tab,null);
TextView finishTextView = (TextView)finishView.findViewById(R.id.tabName);
finishTextView.setText(getText(R.string.text_tab_finish));
finishTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 关注
factory = LayoutInflater.from(this);
final View focusView = factory.inflate(R.layout.tab,null);
TextView focusTextView = (TextView)focusView.findViewById(R.id.tabName);
focusTextView.setText(getText(R.string.text_tab_focus));
focusTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 未开始
mTabHost.addTab(mTabHost.newTabSpec("tab_not_begin")
.setIndicator(notStartview)
.setContent(R.id.textview_notbegin));
// 进行中
mTabHost.addTab(mTabHost.newTabSpec("tab_playing")
.setIndicator(playingView)
.setContent(R.id.textview_playing));
// 已完场
mTabHost.addTab(mTabHost.newTabSpec("tab_finish")
.setIndicator(finishView)
.setContent(R.id.textview_finish));
// 关注
mTabHost.addTab(mTabHost.newTabSpec("tab_focus")
.setIndicator(focusView)
.setContent(R.id.textview_focus));
// 修改宽度,作用两个(关注)与三个字(进行中,已完场)占有不同,三个字宽度大一些
for (int i =0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = DisplayUtil.dip2px(this, 33);
if(i == 1 || i== 2){
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 18;
} else{
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 10;
}
}
// 设置当前选中的Tab
mTabHost.setCurrentTab(1);
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.BLACK);
// tab 选中改变时事件
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
public void onTabChanged(String arg0) {
for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++){
mTabHost.getTabWidget().getChildAt(i).findViewById(R.id.tabName)
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
}
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
.findViewById(R.id.tabName)
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));
}
});
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup();
LayoutInflater factory = null;
// 未开始
factory = LayoutInflater.from(this);
final View notStartview = factory.inflate(R.layout.tab,null);
TextView notStartTextView = (TextView)notStartview.findViewById(R.id.tabName);
notStartTextView.setText(getText(R.string.text_tab_notstart));
notStartTextView
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 进行中
factory = LayoutInflater.from(this);
final View playingView = factory.inflate(R.layout.tab,null);
TextView playingTextView = (TextView)playingView.findViewById(R.id.tabName);
playingTextView.setText(getText(R.string.text_tab_playing));
playingTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));
// 已完场
factory = LayoutInflater.from(this);
final View finishView = factory.inflate(R.layout.tab,null);
TextView finishTextView = (TextView)finishView.findViewById(R.id.tabName);
finishTextView.setText(getText(R.string.text_tab_finish));
finishTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 关注
factory = LayoutInflater.from(this);
final View focusView = factory.inflate(R.layout.tab,null);
TextView focusTextView = (TextView)focusView.findViewById(R.id.tabName);
focusTextView.setText(getText(R.string.text_tab_focus));
focusTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
// 未开始
mTabHost.addTab(mTabHost.newTabSpec("tab_not_begin")
.setIndicator(notStartview)
.setContent(R.id.textview_notbegin));
// 进行中
mTabHost.addTab(mTabHost.newTabSpec("tab_playing")
.setIndicator(playingView)
.setContent(R.id.textview_playing));
// 已完场
mTabHost.addTab(mTabHost.newTabSpec("tab_finish")
.setIndicator(finishView)
.setContent(R.id.textview_finish));
// 关注
mTabHost.addTab(mTabHost.newTabSpec("tab_focus")
.setIndicator(focusView)
.setContent(R.id.textview_focus));
// 修改宽度,作用两个(关注)与三个字(进行中,已完场)占有不同,三个字宽度大一些
for (int i =0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = DisplayUtil.dip2px(this, 33);
if(i == 1 || i== 2){
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 18;
} else{
mTabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 10;
}
}
// 设置当前选中的Tab
mTabHost.setCurrentTab(1);
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.BLACK);
// tab 选中改变时事件
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
public void onTabChanged(String arg0) {
for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++){
mTabHost.getTabWidget().getChildAt(i).findViewById(R.id.tabName)
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab));
}
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
.findViewById(R.id.tabName)
.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_act));
}
});
发表评论
-
android 备用
2014-08-03 13:26 444http://blog.csdn.net/rain_butte ... -
Android中px与dip,sp与dip等的转换工具类(转)
2014-07-16 20:07 600http://www.cnblogs.com/wader201 ... -
android 字体总结
2014-07-15 21:53 548Android提供三种字体:“Sans”,“serif“和“m ... -
mina
2014-07-03 14:12 502http://chwshuang.iteye.com/blog ... -
android获取IMEI
2014-06-17 08:34 534核心代码: Imei = ((TelephonyMan ... -
andorid ui
2014-06-04 22:39 0http://blog.csdn.net/ddddpow/ar ... -
android alarmManage
2014-05-28 21:47 700转自:http://jinguo.iteye.com/bl ... -
adaf
2014-05-27 22:32 0http://www.eoeandroid.com/thr ... -
weixin
2014-05-13 22:42 0android weisixn -
jpajpa
2014-01-28 15:06 508http://www.iteye.com/problems/9 ... -
吉安帕
2014-01-23 22:30 0dfsgdaffgadrgad -
CrudRepository
2013-11-28 19:58 0PagingAndSortingRepository Cr ... -
Android 的第三方报表组件,AChartEngine 案列
2013-08-19 16:48 0http://www.kuaipan.cn/file/id_3 ... -
android sdk adress
2013-08-12 13:23 479developer.android.com/sdk/index ... -
android 结束进程
2013-07-29 22:01 733Android获取apk的版本及包名等信息 http://bl ... -
adnroid 4.0.3去掉虚拟导航栏
2013-07-27 20:54 1030http://blog.csdn.net/wfh1988/ar ... -
andorid全屏
2013-07-27 10:15 791super.onCreate(savedIns ... -
Foursquare
2012-10-12 17:22 0Foursquare -
sqllite brower
2012-09-11 23:05 672http://www.oschina.net/p/sqlite ... -
notice
2012-09-03 21:13 692http://tibaloga.iteye.com/blog/ ...
相关推荐
package zyf.tab.test; import android.app.TabActivity; public class MyTab extends TabActivity { } ``` 3. **重写onCreate()方法**:在MyTab类中,我们需要重写onCreate()方法,初始化TabHost和添加Tab。 ```...
private static final String DATABASE_NAME = "test_scroll_sqlite.db"; public MyDatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void...
import android.app.AlertDialog; import android.app.Dialog; import android.app.TabActivity; import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; import ...
android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:tabGravity="fill" app:tabMode="fixed" /> <androidx.viewpager.widget.ViewPager ...
mTabHost.addTab(mTabHost.newTabSpec("tab_test1") .setIndicator("TAB1") .setContent(R.id.linearLayout2)); mTabHost.addTab(mTabHost.newTabSpec("tab_test2") .setIndicator("TAB2") .setContent(R.id....
在XML布局文件中,TabHost需要设置`android:id="@+id/tabhost"`,TabWidget需要`android:id="@android:id/tabs"`,而FrameLayout需要`android:id="@android:id/tabcontent"`。以下是一个简单的示例: ```xml ...
package com.caigang.test; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.GestureDetector; import android.view.GestureDetector....
【Android FragmentTab 选项卡与 ViewPager 的应用】 在 Android 应用开发中,FragmentTab 选项卡和 ViewPager 是实现多视图切换的常见组件。FragmentTabHost 提供了一个方便的容器,可以用来显示多个 Fragment,...
总的来说,“TabHost_Test”这个例子为开发者提供了一个清晰的示例,展示了如何在Android应用中创建和管理TabHost组件。通过实践这个项目,开发者可以掌握TabHost的基本用法,进一步提升应用的用户体验。
在Android开发中,焦点移动是用户界面交互的重要组成部分,它涉及到控件间的切换,比如在按钮、文本框、...对于`test`这个文件,可能是演示代码或测试用例,通过分析和运行这些代码,可以更直观地学习和实践上述概念。
PagerTabIndicator is a customisable android library that is designed to work with the ViewPager component. Features Support dynamic adapter switch of the ViewPager Customizable tab indicator (bottom/...
Ninja Yet another web browser for Android. Ninja in 酷安 Ninja in 少数派 ...html5test access 509UP with latest Android System WebView. Adblock and whitelist. Readability. Capture whole pag
`mTabHost.newTabSpec`用于创建新的切换卡,每个`TabSpec`都需要一个唯一的标识符(在这里是"tab_test1"和"tab_test2"),一个标签(通过`setIndicator`设置,这里使用了文字和图标)以及一个内容(通过`setContent`...
kolabnotes-android Kolab Notes is the open source note taking app, which makes it possible to sync your notes with Kolab and IMAP server in the Kolab v3 storage format. The apk in the GitHub Releases ...
│ │ ├─androidTest │ │ │ └─java │ │ │ └─com │ │ │ └─bob │ │ │ └─arclayout │ │ │ ApplicationTest.java │ │ │ │ │ └─main │ │ │ AndroidManifest.xml │ │ │ ...
首先,ViewPager是Android SDK提供的一种用于展示多个全屏页面的控件,常用于实现滑动切换的效果,如应用的Tab布局或相册应用。ViewPager通过适配器(PagerAdapter)获取数据并将其转换为可显示的页面。适配器需要...
在提供的`fragment_test.7z`文件中,可能包含了一个示例项目,该项目演示了如何在`Android Studio`中实现上述功能。这可能是通过创建多个`Fragment`类,每个类代表一个界面,然后在`Activity`中设置`ViewPager`和`...