0
HERE İS MY MAİN XML:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:tag="tabPane" />

<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<EditText
    android:id="@+id/address_bar"
    android:layout_width="270px"
    android:layout_height="50px"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="http://" />

<Button
    android:id="@+id/go_Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/address_bar"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/address_bar"
    android:text="GO" />

<Button
    android:id="@+id/new_Tab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/go_Button"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/go_Button"
    android:text="NewTab" />

</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp" />
</LinearLayout> 
</TabHost>

这是我的主要活动文件:

package com.example.androidtablayoutactivity;

import java.net.MalformedURLException;
import java.net.URL;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    TabHost tabHost;
    TabSpec photospec;
    TabSpec songspec;
    Intent songsIntent;
    Button go;
    Button newTab;
   TextView text;
   Intent photosIntent ;
   private int counter=0;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_tab_layout);
       go=(Button)findViewById(R.id.go_Button);
       newTab=(Button)findViewById(R.id.new_Tab);
       text=(TextView)findViewById(R.id.address_bar);
       tabHost = getTabHost();
       go.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            // Tab for Photos
            go();
        }
    });












    }
    public void go(){
         photospec = tabHost.newTabSpec("");
            // setting Title and Icon for the Tab
         URL url = null;
        try {
            url = new URL( text.getText().toString());
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


            if(counter==0){
                photospec.setIndicator(url.getHost().replace("www."," ").replace(".com"," "));
                photosIntent = new Intent(Intent.ACTION_VIEW);
                photosIntent.setClass(this, PhotosActivity.class);
                photosIntent.putExtra("URL1", text.getText().toString());


            photospec.setContent(photosIntent); 
            tabHost.addTab(photospec);
            }
            else{

                tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(0));
                photospec.setIndicator(url.getHost().replace("www."," ").replace(".com"," "));
                photosIntent = new Intent(Intent.ACTION_VIEW);
                photosIntent.putExtra("URL1", text.getText().toString());
                photosIntent.setClass(this, PhotosActivity.class);



            photospec.setContent(photosIntent); 
            tabHost.addTab(photospec);
            }
            counter++;
    }

}

这是我制作浏览器进程的其他活动

package com.example.androidtablayoutactivity;



import com.example.androidtablayoutactivity.SongsActivity.web;

import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

public class PhotosActivity extends Activity{

     WebView web;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photos_layout);

        web=(WebView)findViewById(R.id.web);
        web.setWebViewClient(new web());
        web.getSettings().setJavaScriptEnabled(true);
        Bundle extras = getIntent().getExtras();
        if(extras==null){
            web.loadUrl("");
        }
        else
        {
            web.loadUrl(extras.getString("URL1"));
        }





    }
      public class web extends WebViewClient{

            @Override
            public boolean shouldOverrideUrlLoading(WebView webview,String url){
                webview.loadUrl(url);
                return true;
            }

        }

}

这是它的布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >



    <WebView
        android:id="@+id/web"
        android:layout_width="385dp"
        android:layout_height="fill_parent" />

</LinearLayout>

当我第一次单击 go 按钮时,我正在使用 go 和新选项卡按钮在 android 中使用浏览器 mybrowser 将转到我想要的 url 但是当我再次单击时,我的地址不会改变

4

1 回答 1

0

我正在删除其余部分,因为它不是您要查找的内容, 单击此处

于 2012-10-24T12:40:09.417 回答