編輯:關於android開發
<?xml version="1.0" encoding="utf-8"?>
<!-- 定義當前布局的基本LinearLayout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 定義用戶輸入URL網址的輸入控件 -->
<EditText
android:id="@+id/Et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="www.cnblogs.com/gisoracle/"
android:hint="請輸入要打開的網址"
/>
<!-- 定義用戶打開浏覽器按鈕控件 -->
<Button
android:id="@+id/Btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="點擊打開浏覽器顯示網址"
/>
</LinearLayout>
package com.example.yanlei.yl2;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
//定義布局中的開始跳轉Button控件
private Button btn;
//定義布局中的輸入需要打開的網站地址控件
private EditText Et;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//設置當前Activity的布局文件為activity_main
setContentView(R.layout.activity_main);
//得到浏覽器中的控件對象
findView();
//設置對象的監聽器
setListener();
}
private void setListener() {
//設置btn的點擊監聽器
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//得到用戶輸入的網站地址
String url = Et.getText().toString();
//當用戶輸入不為空時
if (!"".equals(url)) {
//在用戶輸入的地址前加上http://,一般用戶輸入網址的時候不會加
//然後通過處理後的網址構成Uri對象
Uri uri = Uri.parse("http://"+url);
//定義intent對象,通過Intent.ACTION_VIEW來顯示此Uri的內容
Intent it = new Intent(Intent.ACTION_VIEW,uri);
//啟動Activity
startActivity(it);
}
else{
//如果用戶輸入的url為空的話,使用Toast提示用戶
Toast.makeText(MainActivity.this,"請輸入要跳轉的網址...",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void findView() {
//得到布局中的開始加載的Button的對象
btn = (Button)findViewById(R.id.Btn);
//得到布局中的開始加載的EditText的對象
Et = (EditText)findViewById(R.id.Et);
}
}
Android應用開發教程之十六:WebView的簡單使用
最近的項目中看產品文檔的時候,發現設計文檔中”資訊”欄目設計的圖文並茂,有聲有色,感歎之余,發覺如此的布局寫起來太煩太累了&
Android 使用OpenCV的三種方式(Android Studio)
Android 使用OpenCV的三種方式(Android Studio) 其實最早接觸OpenCV是很久很久之前的事了,大概在2013年的5,6月份,當時還是個菜逼(雖
Android安全專項之Xposed劫持用戶名密碼實踐
Android安全專項之Xposed劫持用戶名密碼實踐 Xposed是個強大的工具,可以hook所有的java方法,下面用Xposed來截獲App的用戶名密碼,默
ImageScale,imagescaletype
ImageScale,imagescaletypepackage com.example.imagescale; import android.os.Bundle; i