zoukankan      html  css  js  c++  java
  • Android之简单页面跳转

    Uri.parse方法返回的是一个URL类型,通过URL可以访问一个网络上的或者本地资源,Intent()方法是调用哪个组件来打开这个URL。
    package com.example.web;
    
    import android.net.Uri;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button btn=(Button)findViewById(R.id.btn);
            btn.setOnClickListener(new View.OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Uri uri=Uri.parse("http://translate.google.cn/");
                    Intent intent=new Intent(Intent.ACTION_VIEW,uri);
                    startActivity(intent);
                }
            });
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        
    }

    我们先在values/strings中添加字符:

    <string name="open_ulr">Open</string>

    布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/open_ulr" />
    
    </LinearLayout>

    run:

    不努力,还要青春干什么?
  • 相关阅读:
    $.cookie 使用不了的问题定位过程
    jquery.cookie.js使用介绍
    java 转换 小函数(不断增加中。。。)
    jquery ajax 访问webServer的xml文件
    JS中的prototype【转】
    【转载】习惯决定性格 性格决定命运
    jquery的ajax和原始的ajax这两种方式的使用方法
    ajax readyState的五种状态详解
    一个简单的tcp代理实现
    go tcp使用
  • 原文地址:https://www.cnblogs.com/caidupingblogs/p/5420002.html
Copyright © 2011-2022 走看看