Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 講述 Help 提示框的實現

編輯:關於 Android 程式設計

本文示範如何製作一個能顯示 HTML 格式內容的說明(Help)提示框,適合用來展示版本資訊、功能介紹與作者連結等。

一、字串資源(含 HTML 標籤)

在 strings.xml 中定義帶有 HTML 標籤的說明文字:

<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/services.
    \n
    <b>Feature</b>
    \n
    1) Switch and Stop Tasks/Processes/Apps/Services
    \n
    2) Shows Memory Info and Apps Info
    \n
    3) Uninstall Apps
</string>

二、自訂 HelpDialog

建立一個繼承自 AlertDialog 的類別,把版面載入後設定到對話框中:

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

三、版面配置

用 ScrollView 包住 TextView,讓較長的說明內容可以捲動閱讀:

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

如此一來,點擊說明按鈕時就會彈出一個排版美觀、可捲動的 Help 提示框,把版本資訊與功能介紹清楚呈現給使用者。

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