代码之家  ›  专栏  ›  技术社区  ›  dparnas

安装或更新应用程序后显示模式[关闭]

  •  16
  • dparnas  · 技术社区  · 15 年前

    现在很多Android应用程序在安装或更新后都会显示一个带有最新changelog的模式。

    如何在应用程序最初安装或更新后显示可滚动模式?

    5 回复  |  直到 9 年前
        1
  •  18
  •   Thomas    9 年前

    Try this :

    Android更改日志 您可以轻松地创建、显示和维护Android更改日志对话框。

    其特点是:

    • 用一种简化的语言编写更改日志,如果需要,也可以使用HTML和CSS。。。
        2
  •  16
  •   dparnas    15 年前

    第一部分。检查是否应查看变更日志

            //evaluate if we will show changelog
        try {
            //current version
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            int versionCode = packageInfo.versionCode; 
    
            //version where changelog has been viewed
            SharedPreferences settings = getSharedPreferences(SAPNotePreferences.PREFS_NAME, 0);
            int viewedChangelogVersion = settings.getInt(SAPNotePreferences.KEY_CHANGELOG_VERSION_VIEWED, 0);
    
            if(viewedChangelogVersion<versionCode) {
                Editor editor=settings.edit();
                editor.putInt(SAPNotePreferences.KEY_CHANGELOG_VERSION_VIEWED, versionCode);
                editor.commit();
                displayChangeLog();
            }
        } catch (NameNotFoundException e) {
            Log.w("Unable to get version code. Will not show changelog", e);
        }
    

    第2部分显示changelog对话框

            //load some kind of a view
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.changelog_view, null);
    
        new AlertDialog.Builder(this)
        .setTitle("Changelog")
        .setIcon(android.R.drawable.ic_menu_info_details)
        .setView(view)
        .setNegativeButton("Close", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
              //
          }
        }).show();
    

    第3部分更改日志的布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <ScrollView android:id="@+id/aboutscrollview" 
                android:orientation="vertical"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent">    
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                        <TextView android:text="Thanks for installing ..."
                                android:layout_width="fill_parent" 
                                android:layout_height="wrap_content"
                                android:paddingLeft="15px"              
                                android:layout_gravity="center_vertical"
                                android:textColor="#ffffff" />  
                        <TextView android:text="Changes: "
                                android:layout_width="fill_parent" 
                                android:layout_height="wrap_content"            
                                android:paddingTop="15px"
                                android:paddingLeft="15px"
                                android:textStyle="bold"
                                android:textColor="#ffffff" />
                        <TextView android:text="v2.0:changes..."
                                android:layout_width="fill_parent" 
                                android:layout_height="wrap_content"
                                android:paddingLeft="15px"      
                                android:paddingBottom="10px"            
                                android:textColor="#ffffff" />
                        </LinearLayout>
                </ScrollView>                   
    </LinearLayout>
    
        3
  •  4
  •   Lorensius W. L. T    14 年前
        4
  •  2
  •   Blumer    15 年前

    关于#2,我所做的是为lastVersionNotesSen存储一个设置,该设置保存。。。上次显示的笔记版本号。:)如果该数字小于当前版本,则显示最新版本的注释,并将值更新为当前版本。

        5
  •  2
  •   bk138    14 年前

    为了显示更改日志,您还可以在对话框中本地化(即从res文件夹加载)html:

                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.setTitle(getString(R.string.changelog_dialog_title));
                dialog.setIcon(getResources().getDrawable(R.drawable.icon));
    
                WebView wv = new WebView(getApplicationContext());
                wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8");
                dialog.setView(wv);
    
                dialog.setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
    
                dialog.show();
    

    神奇之处在于如何用res/values编码html“页面”/字符串.xml:

    <string name="changelog_dialog_text">
    <![CDATA[<b>Version 1.3.0:</b>
            <ul>
             <li>Change 1</li>
             <li>Change 2</li>
            </ul> 
    ]]>
    </string>