1

我正在使用 Jdeveloper 11.1.2.4.0 创建启动画面..我已按照http://www.androidaspect.com/2012/12/android-splash-screen-tutorial.html中所述的每个步骤进行操作

但我仍然无法解决问题。

这是我的 splash.java (主要活动)

package mobile;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Window;


public class Splash extends Activity {
     private long ms=0;
     private long splashTime=2000;
     private boolean splashActive = true;
     private boolean paused=false;

    /**
     * @param savedInstanceState
     */

     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

        //Hides the titlebar
         this.requestWindowFeature(Window.FEATURE_NO_TITLE);

         setContentView(R.layout.Splash);

        Thread mythread = new Thread() {
             public void run() {
                 try {
                     while (splashActive && ms < splashTime) {
                         if(!paused)
                             ms=ms+100;
                         sleep(100);
                     }
                 } catch(Exception e) {}
                 finally {
                    Intent intent;
                    intent = new Intent(Splash.this, Home.class);
                    startActivity(intent);
                 }
             }
         };
         mythread.start();
     }
 }

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.company.splash_screen">
  <uses-sdk/>

  <application android:icon="@drawable/adfmf_icon"
    android:label="@string/app_name" android:name="oracle.adfmf.Application">
    <activity android:screenOrientation="fullSensor" android:name=".Splash"      android:noHistory="true" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"
              android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation" android:windowSoftInputMode="adjustPan" >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>


        <activity
             android:name=".Home"
             android:label="@string/title_activity_home" >
         </activity>


    <activity android:name="oracle.adfmf.AMXActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <activity android:name="oracle.adfmf.RemoteURLActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <activity android:name="oracle.adfmf.LocalHTMLActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <activity android:name="oracle.adfmf.phonegap.AdfSpringboardPhoneGapActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <activity android:name="oracle.adfmf.SettingsActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <activity android:name="oracle.adfmf.navbar.MoreTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity> 
    <activity android:name="oracle.adfmf.BlankActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.company.splash_screen" />
      </intent-filter>
    </receiver>
    <service android:name=".GCMIntentService" />
  </application>

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.RECEIVE_SMS" />
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />
  <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <permission android:name="com.company.splash_screen.permission.C2D_MESSAGE" android:protectionLevel="signature" />
  <uses-permission android:name="com.company.splash_screen.permission.C2D_MESSAGE" />
  <!-- App receives GCM messages. -->
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <!-- GCM connects to Google Services. -->
  <uses-permission android:name="android.permission.INTERNET" /> 
  <!-- GCM requires a Google account. -->
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <!-- Keeps the processor from sleeping when a message is received. -->
  <uses-permission android:name="android.permission.WAKE_LOCK" /> 

</manifest>

在 res/layout/ 文件夹中,我有 splash.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >

    <ImageView
         android:id="@+id/image"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/background" />

    <ProgressBar
         android:id="@+id/progressBar1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@id/image"
         android:layout_gravity="center_horizontal" >
     </ProgressBar>

</LinearLayout> 

和 home.xml(第二个活动)

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical" >

    <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:layout_marginTop="20dip"
         android:text="HomeScreen"
         android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

在两个 .java 文件(splash.java 和 home.java)中,setContentView(R.layout.Splash) 处显示错误;和 setContentView(R.layout.Home); 响应...

4

2 回答 2

4

您的R.java文件未正确生成。

清理项目并重新构建它。

项目 -> 清理

如果这不能解决问题,请检查 XML 文件中的错误。XML 文件中的错误会阻止 R.java 的生成。

一旦您确定一切都正确,您可以清理项目并重新构建它。

或者您可以手动删除 R.java然后构建项目,该项目将R.java再次重新生成。

注意永远不要使用import android.r,即使你看到 eclipse 建议它。

于 2013-06-04T06:07:16.000 回答
0

你用力导入它,

把它放在你的进口中

import (Your package Name ex:com.android.user).R

并确保在 (Project->gen>projectname->R.java) 中有 R.java 文件,如果你不去(右键单击项目-> android 工具-> 修复项目属性。)

于 2013-06-04T06:04:54.730 回答