2017-03-11 17 views
0

私のアンドロイドアプリケーションでこのオーダーを実行する方法を教えてもらえますか?私はそれがスプラッシュの後に表示されるようにする方法がわからないランチャースプラッシュ画面の後にメインアクティビティではなく別のアクティビティを起動する

2)イントロスライダー(WelcomeActivity)。..として行っている

1)スプラッシュスクリーン(SplashActivity)..

3)主なアクティビティ..歓迎の後に表示したい、または "GOT IT"ボタンをクリックして起動させます。

ありがとうございます。

+0

マニフェストでWelomeActivityを宣言している限り、startActivity()インテントを使用して呼び出すことができます –

答えて

1

私が正しい場合は、インテントとハンドラを使用する方法が求められます。まず、splashActivity.javaは次のようになります。

public class SplashActivity extends Activity{ 

//timer in miliseconds, 1000ms = 1s// 
private static int SPLASH_TIME_OUT = 2000; 

//create first screen showed when app is launched// 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splash); 

    new Handler().postDelayed(new Runnable() { 
     //showing splashscreen with a timer // 

     @Override 
     public void run() { 
      //this is executed once the timer is over// 

      Intent i = new Intent(SplashActivity.this, WelcomeActivity.class); 
      startActivity(i); 
      finish(); 

     } 
    },SPLASH_TIME_OUT); 

} 
} 

その後、例えばのAndroidManifest.xml で、メニューの活動とスプラッシュ活動を宣言。

例を参照してください 、あなたの歓迎活動の後にあなたの主な活動を開くだけでコピーして、必要な変更を行う、あなたのWelcomeActivityにSplashActivity.javaためのコードを貼り付け、 が、ボタンを使用して開く方法については、方法については、次に
<activity 
     android:name=".SplashActivity" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".WelcomeActivity" 
     android:screenOrientation="sensor" /> 
    <activity 
     android:name=".MainActivity" 
     android:screenOrientation="sensor" /> 

以下のコード 最初にあなたのボタンをオフにしてください。あなたのデザインはすでにあなたのデザインに入っていますactivity_welcome.xml 私はあなたが書いているかのプログラムを知らないか、あなたがこれまでにそれを設計しているか、これは単なる一例であり、あなたのかもしれないです:あなたWelcomeActivity.java

public class WelcomeActivity extends Activity { 
Button button; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_welcome); 
    addListenerOnButton(); 

} 
public void addListenerOnButton() { 

    final Context context = this; 

    button = (Button) findViewById(R.id.button); 

    button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      Intent intent = new Intent(context, MainActivity.class); 
      startActivity(intent); 
      finish(); 
      Toast.makeText(context, "MainActivity Opened.", Toast.LENGTH_SHORT).show(); 

     } 

    }); 
} 
} 

NBで

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_welcome" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.domainname.yourappname.WelcomeActivity" 
android:background="@drawable/splash" 

<Button 
     android:text="@string/got it" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/button" 
     style="@style/Widget.AppCompat.Button.Borderless" 
     android:textAlignment="center" 
     android:textSize="30sp" 
     android:layout_marginTop="41dp" 
    android:textColorHighlight="@android:color/transparent" 
    android:textColorHint="@android:color/transparent" 
    android:layout_below="@+id/textView3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

</RelativeLayout> 

あなたの実際のコードが正しく動作するように調整する必要があります。

0

あなたの質問に答えてください。

まず、すべての活動はそれほどのようなあなたのマニフェストで宣言されていることを確認してください。そして、スプラッシュタイマーの終了時SplashActivityでこれを宣言し

<application 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".SplashActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".WelcomeActivity" /> 
     <activity android:name=".MainActivity" /> 
</application>  

//If you're using a "Timer" to count down splash screen 
new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       Intent intent = new Intent(SplashActivity.this, WelcomeActivity.class); 
       startActivity(intent); 

      } 
     }, 2000); 

あなたWelcomeActivityではどこにアクティビティの最後を呼び出します。

Intent intent = new Intent(WelcomeActivity.this, MainActivity.class); 
    startActivity(intent); 

詳細情報次の活動のために余分なデータを追加する方法を含むインテントhereを使用して、別のアクティビティを開始することについて説明します。希望が役立ちます。

関連する問題