Reputation: 3891
I've just created a new application. The main activity contains a button which when pressed starts a new activity like this:
public void onClick(View v) {
switch (v.getId()) {
case R.id.activity_main_add:
Intent i = new Intent(this, Activity2.class);
startActivity(i);
break;
}
}
This is how the Activity2 looks like:
public class Activity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_task);
}
}
The problem now is that the main activity shows the actionbar, but the second activity won't. I don't know where the problem could be, any suggestions? Here's the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"
android:label="@string/activity_2">
</activity>
<activity android:name=".SettingsActivity"
android:label="@string/action_settings">
</activity>
</application>
</manifest>
And here's the style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>
Any suggestions?
Upvotes: 0
Views: 75
Reputation: 30601
Change your second Activity
to:
public class Activity2 extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_task);
}
}
Try this. This will work.
Upvotes: 1