<uses-permission android:name="android.permission.INTERNET" />
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/viewSwitcher1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Enter Your Site" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" > </EditText> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="Go" /> </RelativeLayout> </TableLayout> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tableLayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="0dp" > <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent"/> </TableLayout> </ViewSwitcher>
package com.myapp; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.webkit.WebView; import android.widget.Button; import android.widget.EditText; import android.widget.ViewSwitcher; public class MainActivity extends Activity{ ViewSwitcher Vs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // viewSwitcher1 Vs = (ViewSwitcher) findViewById(R.id.viewSwitcher1); // button1 (Go) Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Vs.showNext(); // editText1 EditText txtUrl = (EditText) findViewById(R.id.editText1); // webView1 WebView WebViw = (WebView) findViewById(R.id.webView1); WebViw.getSettings().setJavaScriptEnabled(true); WebViw.loadUrl(txtUrl.getText().toString()); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
String url = "http://www.example.com"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i);
package com.myapp; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.webkit.WebView; import android.widget.Button; import android.widget.EditText; import android.widget.ViewSwitcher; public class MainActivity extends Activity{ ViewSwitcher Vs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // viewSwitcher1 Vs = (ViewSwitcher) findViewById(R.id.viewSwitcher1); // button1 (Go) Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Vs.showNext(); // editText1 EditText txtUrl = (EditText) findViewById(R.id.editText1); String url = txtUrl.getText().toString(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท