Back to project page musetoolkit.
The source code is released under:
GNU General Public License
If you think the Android project musetoolkit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.musetoolkit; /*w ww . j a va2 s. co m*/ import android.annotation.SuppressLint; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.widget.ImageView; import android.widget.TabHost; import android.widget.Toast; import android.widget.TabHost.TabSpec; import android.widget.TabWidget; import android.widget.TextView; public class MainActivity extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); // ??Activity?????? setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // tabHost = (TabHost) findViewById(R.id.tabhost); TabWidget tabWidget = tabHost.getTabWidget(); tabHost.setup(); LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true); tabHost.setBackgroundColor(Color.argb(150, 22, 70, 150)); updateTab(tabHost);//????Tab?????????? // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, SignalActivity.class); //?????Tab??Activity???Intent // Initialize a TabSpec for each tab and add it to the TabHost //??????????? spec = tabHost.newTabSpec("signal").setIndicator("????", res.getDrawable(R.drawable.ic_tab_signal)).setContent(intent); //?????????? tabHost.addTab(spec); //???????????TabHost?? // Do the same intent = new Intent().setClass(this, TestActivity.class); spec = tabHost.newTabSpec("test").setIndicator("??", res.getDrawable(R.drawable.ic_tab_test)).setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, CalcActivity.class); spec = tabHost.newTabSpec("calc").setIndicator("??", res.getDrawable(R.drawable.ic_tab_calc)).setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, TheoryActivity.class); spec = tabHost.newTabSpec("theory").setIndicator("????", res.getDrawable(R.drawable.ic_tab_theory)).setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, MoreActivity.class); spec = tabHost.newTabSpec("more").setIndicator("??", res.getDrawable(R.drawable.ic_tab_more)).setContent(intent); tabHost.addTab(spec); /* * ?????????????????????4848??????????????????????????? */ TabWidget tw = tabHost.getTabWidget(); for (int i = 0; i < tw.getChildCount(); i++) { TextView tv=(TextView)tw.getChildAt(i).findViewById(android.R.id.title); ImageView iv=(ImageView)tw.getChildAt(i).findViewById(android.R.id.icon); iv.setPadding(0, -8, 0, 0); tv.setPadding(0, 0, 0, -2); tv.setTextSize(12); } // ???????????Tabhost???????????????????????????????????????????????? for (int i =0; i < tabWidget.getChildCount(); i++) { tabWidget.getChildAt(i).getLayoutParams().height = 120; tabWidget.getChildAt(i).getLayoutParams().width = 65; TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title); tv.setTextSize(12); tv.setTextColor(this.getResources().getColorStateList(android.R.color.white)); } // tabHost.setCurrentTab(2); } /** * ??Tab???????????? * @param tabHost */ private void updateTab(final TabHost tabHost) { for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { View view = tabHost.getTabWidget().getChildAt(i); TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextSize(12); tv.setTypeface(Typeface.SERIF, 2); // ??????? if (tabHost.getCurrentTab() == i) {//?? view.setBackgroundDrawable(getResources().getDrawable(R.drawable.png02));//???????? tv.setTextColor(this.getResources().getColorStateList( android.R.color.black)); } else {//???? view.setBackgroundDrawable(getResources().getDrawable(R.drawable.png01));//???????? // view.setBackground(getResources().getDrawable(R.drawable.sine_bg)); tv.setTextColor(this.getResources().getColorStateList( android.R.color.white)); } } } /** * ???????????? * * ??? Activity ?? TabActivity ? onKeyDown ????????? dispatchKeyEvent * ??? Activity ? onKeyDown ?????? */ //???????Back????????????????? //????????import???Android? //import android.view.KeyEvent; //import android.widget.Toast; private long exitTime = 0; @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { this.exitApp(); } return true; } return super.dispatchKeyEvent(event); } /** * ????? */ private void exitApp() { // ??2??????? if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(MainActivity.this, "??????????", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { finish(); } } }