安装或更新应用程序后显示模态

dpa*_*nas 15 android modal-dialog

很多Android应用程序现在都会在安装或更新后显示最新更改日志的模式.

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

小智 19

试试这个:

借助Android Change Log,您可以轻松创建,显示和维护Android更改日志对话框.

特点是:

  • 仅显示新的或整个更改日志
  • 在新安装的应用程序或新应用程序版本的首次启动时显示
  • 用简化的语言编写更改日志,但如果需要也使用HTML和CSS ...


dpa*_*nas 16

结束以下代码第1部分.检查是否应该查看更改日志

        //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);
    }
Run Code Online (Sandbox Code Playgroud)

第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();
Run Code Online (Sandbox Code Playgroud)

第3部分使用changelog进行布局

<?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>
Run Code Online (Sandbox Code Playgroud)