編輯:開發入門
本節將示範如何建立一個 Android Help 提示框。這個提示框可以顯示版本資訊、作者、網站與功能說明,常見於應用程式的「關於」或「說明」頁面。
import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
import com.iwidsets.task.manager.R;
public class HelpDialog extends AlertDialog {
public HelpDialog(Context context) {
super(context);
final View view = getLayoutInflater().inflate(R.layout.help_dialog, null);
setButton(context.getText(R.string.close), (OnClickListener) null);
setIcon(R.drawable.icon);
setTitle("AndTask version:" + R.string.version);
setView(view);
}
}
<?XML version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="@string/help_dialog_text"
android:padding="6dip" />
</ScrollView>
</FrameLayout>
<string name="help_dialog_text"> <i>Author: fonter.yang</i> \n <i><a href="https://www.iwidsets.com">https://www.iwidsets.com</a></i> \n <i>AndTask - android Task Manager</i> \n It is an easy-to-use task management software. It allows you to switch on or off running programs, apps and services. \n <b>Feature</b> \n 1) Switch and stop tasks, processes, apps and services \n 2) Shows memory info and app info \n 3) Uninstall apps </string>
這個做法的核心是 AlertDialog 搭配自訂 View。透過 getLayoutInflater().inflate 載入自訂版面,再用 setView 放入對話框中,即可讓提示框呈現更豐富的內容。
用 Eclipse 開發 Android 應用程式(三):版面配置、清單檔與模擬器除錯
main.xml 這個範例應用包含一個活動與一個視圖。應用裡有個名為 main.xml 的檔案,代表活動主 UI 的視覺層面。請注意,main.xml 裡並未指定這個版面
用 Eclipse 開發 Android 應用程式(二):安裝 SDK 與打造 SaySomething 應用
Android Software Developer Kit 我們已經大致了解 Android 平台,現在來談談如何把 Eclipse 環境配置得能支援 Android
智慧交通之路(一):用 Google Maps 與 GTFS 打造你的通勤後盾
公共交通能紓解擁擠、削減由此而生的污染,順帶降低通勤者的壓力與花費。今天有為數眾多的網站與行動應用,正幫著世界各地的乘客、逛街的人和旅人變成「有道德的利己主義者」——把各
對 Android 開發者有益的 40 條優化建議
Android 開發不只是把功能做出來,還需要考慮相容性、效能、記憶體、測試與使用者體驗。以下整理 40 條實用建議,適合初學者與中階開發者參考。 先尋找與需求相似的