简体   繁体   中英

Application name bar disappears after switching to new activity

Basically, the problem is pretty straight-forward if you read the title.

I started my test application for testing purposes and when I'm at the main menu, there is that bar with the application name above and when I click on any button that triggers a new activity, the bar disappears.

http://i.stack.imgur.com/uI70f.png

After clicking, in this example, "What's the meaning of life?" button, the result looks like this

http://i.stack.imgur.com/7mvmY.png

The codes that are used in order to make the button are as follows:

options_menu.xml

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="What is the meaning of life?"
    android:onClick="ShowLifeMeaning"
    android:textAllCaps="false"
    android:id="@+id/button2"
    android:layout_below="@+id/button"
    android:layout_centerHorizontal="true" />

Life.java

public class Life extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.meaning_of_life);
}

@Override
public void onBackPressed() {
    finish();
}

MainActivity.java

public void ShowLifeMeaning(View view) {

    startActivity(new Intent(this, Life.class));

}

You can try using

public class Life extends ActionBarActivity

Hi I think it 's because of theme, in your manifest file maybe you right this code for theme : theme."your theme".NoActionbar or something like this. if you remove it , it would be correct

You need to use ActionBarActivity.
But this class being deprecated , you can use AppCompatActivity with which you can support actionBar starting from API 7 and it supports fragments as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM