Android练习

package leadingmis.mobile.main;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;


public class MainActivity extends TabActivity  implements
 OnCheckedChangeListener {
 
    private TabHost mHost;
    private Intent mMBlogIntent;
    private Intent mMoreIntent;
    private Intent mInfoIntent;
    private Intent mSearchIntent;
    private Intent mUserInfoIntent;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
       
        Button btn = (Button)findViewById(R.id.button );
        btn.setOnClickListener(new ShowSonActivity());
        /*
        btn.setOnClickListener(new View.OnClickListener() {   
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "dd", 1);
   }
  });
  */
       
        // ~~~~~~~~~~~~ 初始化
        this.mMBlogIntent = new Intent(this, HomeListActivity.class);
        this.mSearchIntent = new Intent(this, SearchSquareActivity.class);
        this.mInfoIntent = new Intent(this, MessageGroup.class);
        this.mUserInfoIntent = new Intent(this, MyInfoActivity.class);
        this.mMoreIntent = new Intent(this, MoreItemsActivity.class);

        initRadios();
       
        //setupIntent();
    }
   
    class ShowSonActivity implements View.OnClickListener{

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   Intent intent = new Intent();
   //intent.putExtra("wch", "这是子页面");
   intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
   intent.setClass(MainActivity.this, SonActivity.class );
   MainActivity.this.startActivity(intent);
  }   
    }
   
    /**
     * 初始化底部按钮
     */
    private void initRadios() {
         ((RadioButton) findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_button1)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_button2)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_button3)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_button4)).setOnCheckedChangeListener(this);        
    }
   
    /**
     * 切换模块
     */
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            switch (buttonView.getId()) {
            case R.id.radio_button0:
                this.mHost.setCurrentTabByTag("mblog_tab");
                break;
            case R.id.radio_button1:
                this.mHost.setCurrentTabByTag("message_tab");
                break;
            case R.id.radio_button2:
                this.mHost.setCurrentTabByTag("userinfo_tab");
                break;
            case R.id.radio_button3:
                this.mHost.setCurrentTabByTag("search_tab");
                break;
            case R.id.radio_button4:
                this.mHost.setCurrentTabByTag("more_tab");
                break;
            }
        }
    }
   
    private void setupIntent() {
        this.mHost = getTabHost();
        TabHost localTabHost = this.mHost;

        localTabHost.addTab(buildTabSpec("mblog_tab", R.string.main_home,
                R.drawable.icon_1_n, this.mMBlogIntent));

        localTabHost.addTab(buildTabSpec("message_tab", R.string.main_news,
                R.drawable.icon_2_n, this.mInfoIntent));

        localTabHost.addTab(buildTabSpec("userinfo_tab", R.string.main_my_info,
                R.drawable.icon_3_n, this.mUserInfoIntent));

        localTabHost.addTab(buildTabSpec("search_tab", R.string.menu_search,
                R.drawable.icon_4_n, this.mSearchIntent));

        localTabHost.addTab(buildTabSpec("more_tab", R.string.more,
                R.drawable.icon_5_n, this.mMoreIntent));

    }
   
    private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
            final Intent content) {
        return this.mHost
                .newTabSpec(tag)
                .setIndicator(getString(resLabel),
                        getResources().getDrawable(resIcon))
                .setContent(content);
    }
}

 

 

          android:name=".SonActivity">
  

 

2、

JS中调用java方法
webView.addJavaScriptInterface(new ContactPlugin(),"itcast");
public class ContactPlugin{
 public void getContacts(){
 
 }
}
在JS中调用:οnlοad="javascript:itcast.getContactts()"
在Java中调用JS方法,getContacts()方法中:webView.loadUrl("Javascript:show()");

添加Menu控件
@Override
public boolean onCreateOptionMenu(Menu menu)
{
  menu.add(0,1,1,"退出");
  menu.add(0,2,2,"关于");
  return super.onCreateOption(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
 if(item.getItemId() == 1){
  finish()
 }
 return super.onOptionItemSelected(item);
}

 

3、WebView隐藏滚动条

webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY)
WebView 中 android:scrollbarSize="0dip" 加上这句就好了

 

你可能感兴趣的:(Android)