Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發 >> 開發入門

Android 講述 Help 提示框

編輯:開發入門

本節將示範如何建立一個 Android Help 提示框。這個提示框可以顯示版本資訊、作者、網站與功能說明,常見於應用程式的「關於」或「說明」頁面。

HelpDialog.java

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);
    }
}

help_dialog.xml

<?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>

strings.xml

<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 放入對話框中,即可讓提示框呈現更豐富的內容。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved