安卓Android 按鈕案例
Android Button Example | Examples Java Code Geeks
安卓的UI中最基本設計是按鈕操作,該文圖示瞭如何用Eclipse視覺化給安卓Android專案增加按鈕。
首先建立一個Android Activity:
執行程式碼效果如下:
安卓的UI中最基本設計是按鈕操作,該文圖示瞭如何用Eclipse視覺化給安卓Android專案增加按鈕。
首先建立一個Android Activity:
完成後,在res/layout/main.xml檔案被建立:
開啟這個main.xml, Eclipse出現如下視覺化介面:
將按鈕從左邊form widgets拖到右邊介面中,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="www.javacodegeeks.com" />
</LinearLayout>
然後,回到layout頁面,建立下面java檔案:
package com.javacodegeeks.android.buttonexample; 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 MainActivity extends Activity { private Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addListenerOnButton(); } public void addListenerOnButton() { //Select a specific button to bundle it with the action you want button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent openBrowser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.javacodegeeks.com")); startActivity(openBrowser); } }); } } <p class="indent"> |
執行程式碼效果如下:
[該貼被admin於2012-12-12 15:50修改過]
相關文章
- 安卓開發學習-按鈕控制元件安卓控制元件
- Android 點選按鈕跳轉Android
- Android處理按鈕重複點選Android
- Android | 使用 AspectJ 限制按鈕快速點選Android
- Fiori Elements List Report table 裡的普通按鈕,Global 按鈕 和 Determining 按鈕
- android音視訊指南-響應媒體按鈕Android
- 高亮按鈕
- Android優雅地處理按鈕重複點選Android
- Flutter Button(按鈕)Flutter
- 小程式按鈕
- 復飛按鈕
- 核取方塊和切換按鈕的7個使用案例
- 使用SVG實現的一個Android播放/暫停按鈕SVGAndroid
- Android Material Design控制元件使用(二)——FloatButton TextInputEditText TextInputLayout 按鈕AndroidMaterial Design控制元件
- Android joystick,安卓模擬搖桿Android安卓
- HTML input image 按鈕HTML
- HTML input button 按鈕HTML
- HTML input image按鈕HTML
- HTML input button按鈕HTML
- vue 封裝按鈕Vue封裝
- VBA命令按鈕操作
- 瞭解下Foundation 按鈕
- Android Studio 模擬器 安卓12 安裝MagiskAndroid安卓
- 安卓案例:聯選系部與專業安卓
- 安卓(Android)開發基礎知識安卓Android
- Qt更改按鈕樣式 (以QSpinBox使用左右按鈕樣式為例)QT
- 乾貨!必看創意按鈕設計,打造真正的按鈕誘惑
- 小程式 · wx.showActionSheet在安卓無取消按鍵安卓
- JFrame容器和JButton按鈕
- flutter demo (二):禁用按鈕Flutter
- 單選多選按鈕
- [JS]bootstrapTable新增操作按鈕JSbootAPT
- HTML input reset 重置按鈕HTML
- Python文字框與按鈕Python
- Tkinter (02) 按鈕部件 Button
- LabVIEW的自定義按鈕View
- 按鈕式超連結
- 瞭解下Foundation 按鈕組
- MFC 捕獲按鈕 按下和抬起 (轉)