nua*_*ala 2 android splash-screen
目前我正在开发一个android-phonegap项目.
在应用程序加载index.html之前,有一些本机代码正在运行.详细说明是AsyncTask中的SD卡(如果有的话).
我设法在A.Task工作时显示进度条,但此外我想在后台添加一个Splash屏幕.我主要使用Phonegap,只是从本机代码开始.所以我对所有这些布局,主题以及您在.xml文件中定义的其他内容感到困惑.我很确定这对于更大的UI设计也是一个好主意,但对于我现在想要的简单的Splash屏幕,它感觉就像一个完全矫枉过正.
这是来自源代码的片段.直接前进.onCreate()调用AsyncTask做一些工作并在它的PostExecute方法中启动PhoneGap.我希望屏幕出现在onCreate方法或onPreExecute中.作业完成后,屏幕上我将关闭onPostExecute()中的屏幕.我还添加了评论来说明我的想法.
public class myAct extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Show Splash here or in onPreExecute()!
new myAsTa().execute();
}
}
class myAsTa extends AsyncTask<Void, Integer, Boolean> {
ProgressDialog dialog = new ProgressDialog(myAct.this);
@Override
protected void onPreExecute() {
//or show splash here!
dialog.setMessage("Cool Progressbar!");
dialog.show();
super.onPreExecute();
}
protected Boolean doInBackground(Void... values) {
//magician at work!
return true;
}
@Override
protected void onProgressUpdate(Integer... values) {
//insult user here
}
protected void onPostExecute(Boolean result) {
dialog.dismiss();
//dismiss splashscreen
//start Phonegap
}
}
Run Code Online (Sandbox Code Playgroud)
感谢阅读和你的帮助:)
我在这里做过这样的启动画面.这会加载启动布局,并在加载应用程序时直接从系统触发(AndroidManifest.xml)
<activity android:name=".SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
屏幕上显示的内容定义在setContentView(R.layout.splash);- 这个布局基本上是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/desktop_rhq"
>
<TextView android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/loading"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
其中定义了背景图像和一些要显示的文本.说实话,我在启动时没有考虑方向更改 - 我想这会重新启动后台任务.
| 归档时间: |
|
| 查看次数: |
10772 次 |
| 最近记录: |