Demo for Android Tab Widget
2012-11-21 00:51
267 查看
按照Google Android SDK的例子,做了tab view的练习,其中破折颇多。
先是layout的图形界面无法显示TabWidget (TabHost);再是切换Tab的时候图标并没有变化;还有git的TGitCache导致CPU过高,机器发热大,死机的问题。为了解决第一个问题,更新了SDK,还有Eclipse IDE中的更新,但是却出现第二次运行(Run)只到27%的问题。查了以后才知道,这个bug需要先运行模拟器,然后再run就可以了。
通过练习,敲代码,会加深不少印象,在这个过程中,遇到了知识点就去补充。虽然可能会记不住,很快忘掉,但是先在脑子里留个印象对以后再来会有好处。
贴一下关键文件的代码,自行查找知识点,下载完整代码请点击:iBuoTabView。
Posted by ian at 06:45 Tagged with: Android, View, Widget
先是layout的图形界面无法显示TabWidget (TabHost);再是切换Tab的时候图标并没有变化;还有git的TGitCache导致CPU过高,机器发热大,死机的问题。为了解决第一个问题,更新了SDK,还有Eclipse IDE中的更新,但是却出现第二次运行(Run)只到27%的问题。查了以后才知道,这个bug需要先运行模拟器,然后再run就可以了。
通过练习,敲代码,会加深不少印象,在这个过程中,遇到了知识点就去补充。虽然可能会记不住,很快忘掉,但是先在脑子里留个印象对以后再来会有好处。
贴一下关键文件的代码,自行查找知识点,下载完整代码请点击:iBuoTabView。
package ian.study.demo; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.StateListDrawable; import android.os.Bundle; import android.widget.TabHost; import android.widget.TextView; import android.widget.TabHost.OnTabChangeListener; import android.widget.Toast; import android.util.Log; public class HelloTabWidget extends TabActivity implements OnTabChangeListener{ public static final String TAG = "TabDemo"; private TabHost mTabHost = null; // The activity TabHost private static final int TAB_ARTISTS = 0; private static final int TAB_ALBUMS = 1; private static final int TAB_SONGS = 2; private static final int TAB_MORE = 3; private static final int TAB_ID = 0; private static final int TAB_TITLE = 1; private static final String[][] mTabTag={ {"artists", "Artists"}, {"albums", "Albums"}, {"songs", "Songs"}, {"more", "..."}, }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = getTabHost(); Resources res = getResources(); // Resource object to get Drawables TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = mTabHost.newTabSpec(mTabTag[TAB_ARTISTS][TAB_ID]). setIndicator(mTabTag[TAB_ARTISTS][TAB_TITLE], res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent); mTabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, AlbumsActivity.class); spec = mTabHost.newTabSpec(mTabTag[TAB_ALBUMS][TAB_ID]). setIndicator(mTabTag[TAB_ALBUMS][TAB_TITLE], res.getDrawable(R.drawable.ic_tab_albums)) .setContent(intent); mTabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = mTabHost.newTabSpec(mTabTag[TAB_SONGS][TAB_ID]). setIndicator(mTabTag[TAB_SONGS][TAB_TITLE], res.getDrawable(R.drawable.ic_tab_songs)) .setContent(intent); mTabHost.addTab(spec); /* * add one more tab for testing Drawable in code. */ StateListDrawable drawIcon; drawIcon = new StateListDrawable(); drawIcon.addState(new int[] {android.R.attr.state_enabled}, res.getDrawable(R.drawable.icon)); intent = new Intent().setClass(this, SongsActivity.class); spec = mTabHost.newTabSpec(mTabTag[TAB_MORE][TAB_ID]). setIndicator(mTabTag[TAB_MORE][TAB_TITLE], drawIcon).setContent(intent); mTabHost.addTab(spec); mTabHost.setCurrentTab(2); mTabHost.setOnTabChangedListener(this); } public void onTabChanged(String tabId) { Activity activity = getLocalActivityManager().getActivity(tabId); Log.d(TAG, "tabId=" + tabId); Toast.makeText(this, tabId, Toast.LENGTH_SHORT).show(); if((tabId == mTabTag[TAB_MORE][TAB_ID]) && (activity != null)) { /* do something when focus to info tab * Just create a new TextView and set its text. */ TextView textview = new TextView(activity); textview.setText(getString(R.string.app_name) + " by Ian@blog.ibuo.org"); activity.setContentView(textview); } } }
Posted by ian at 06:45 Tagged with: Android, View, Widget
相关文章推荐
- android 标签页的实现 TabHost TabWidget TabActivity
- Android-修改TabWidget字体大小颜色及对齐
- Android中TabWidget的使用
- Android TabWidget/TabHost的使用
- Android TabHost,TabWidget选项卡总结
- Android选项卡实现之TabHost/TabSpec/TabWidget
- android用户界面-组件Widget-选项卡Tab
- Android练习-----选项卡(TabHost)、(TabWidget)、(FrameLayout)
- 可删除超炫&多种特效的Card视图(改造自cardsui-for-android开源项目),提供DEMO下载
- Android ViewFlipper within TabHost for Tabs with different Views ... and better memory footprint
- Android 切换卡(TabWidget)
- QT 5.4.1 for Android Ubuntu QtWebView Demo
- Android TabWidget
- Android中AppWidget的学习整理(附demo)
- android:使TabWidget在底部
- android用户界面-组件Widget-选项卡Tab
- android startActivityForResult和setResult详情及Demo
- Android 手机电话薄TabWidget多标签切换卡效果
- ArcGis for Android (studio)环境介绍与demo
- android简易版切换卡TabWidget