Android Button example
main.xml
<?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/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button - Go to 百度" />
</LinearLayout>
java
package com.cjp.buttondemo;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class ButtonDemo extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton() {
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com"));
startActivity(browserIntent);
}
});
}
}
更多相关文章
- Android UI技巧(一)——Android中伸缩自如的9patch图片切法,没有美
- 关于android 4.4以上版本从相册选取图片加载不了图片的问题
- Android中 加载一张大图片Caused by: java.lang.OutOfMemoryErro
- Android 异步获取网络图片并处理图片Out Of Memory 内存溢出问题
- Android图片缩放效果代码
- Android 与H5交互心得(Base64图片)
- Android 调用系统的分享[完美实现同时分享图片和文字]
- Android学习札记51:在TextView显示插入的图片
- DataBinding赋值本地图片src