android之打开网页

时间:2023-03-09 08:53:15
android之打开网页

首先改写strings.xml文件

代码如下:

<resources>

    <string name="app_name">Intent应用</string>
<string name="open_name">标准Action操作</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string> </resources>

  然后改写activity_main.xml文件

代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/mybut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打开网页"/>
</LinearLayout>

  最后改写MainActivity类

代码如下:

package com.example.myclock;

import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.Vibrator;
import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.Chronometer.OnChronometerTickListener; public class MainActivity extends Activity {
private Button mybut = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mybut = (Button)super.findViewById(R.id.mybut);
this.mybut.setOnClickListener(new OnClickListenerlmpl());
}
private class OnClickListenerlmpl implements OnClickListener{
public void onClick(View view){
Uri uri = Uri.parse("http://www.mldn.cn");
Intent it = new Intent();
it.setAction(Intent.ACTION_VIEW);
it.setData(uri);
MainActivity.this.startActivity(it);
}
}
}

  运行效果:

android之打开网页