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>
这是我的MAİNACTİVİTYFİLE:
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++;
}
}
在这里,我的其他ACTİVİTYWHİCHMAKİNGBROWSER流程
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;
}
}
}
HEREİSİTSLAYOUTFİLE
<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和新标签按钮当我第一次点击时按钮mybrowser将转到我想要的网址然而当我点击一次时我的地址不会改变