0

I am trying to get my action bar to have the up arrow to go back to my menu why will it not work...this is my code...it works if I have a web view on another app what will it not work here?.....can someone please help and no one liners and give me a reason it will not work...I have tried to redo it and it still will not work!!

import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class About extends TabActivity {

private static TabHost tabHost;
private static Intent intent;
private static TabHost.TabSpec spec;


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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    tabHost = getTabHost();

    intent = new Intent().setClass(this, About1.class);
    spec = tabHost.newTabSpec("about").setIndicator("ABOUT US").setContent(intent);
    tabHost.addTab(spec);


    intent = new Intent().setClass(this, About2.class);
    spec = tabHost.newTabSpec("instructors").setIndicator("INSTRUCTORS").setContent(intent);
    tabHost.addTab(spec);


    intent = new Intent().setClass(this, About3.class);
    spec = tabHost.newTabSpec("disciplines").setIndicator("DISCIPLINES").setContent(intent);
    tabHost.addTab(spec);



}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent listintent = new Intent(About.this,Menu.class);
        startActivity(listintent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

4

3 回答 3

0

不错的尝试,但每个人都错了......这是一件简单的事情......我有时讨厌java......

    public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent listintent = new Intent(About.this,
                Menu.class);
        startActivity(listintent);
        return true;

问题是这条该死的线:

Intent listintent = new Intent(About.this, Menu.class);

在我上面的代码中!!!它不可能是这样的,它必须是这样的:

Intent listintent = new Intent(About.this, 
                    Menu.class);

那是疯狂的粗鲁!

于 2013-08-14T06:37:47.357 回答
0

在 onCreate() 方法中设置以下代码

ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

然后就在 onCreate() 方法下面

@Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        switch (item.getItemId()) 
        {
        case android.R.id.home:
            finish();
            Intent listintent = new Intent(About.this,Menu.class);
            startActivity(listintent);

        }
        return super.onOptionsItemSelected(item);
    }

希望对你有帮助……!!

于 2013-08-08T05:04:19.980 回答
0

尝试像这样使用它:

ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true); 
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
于 2013-08-08T03:59:26.087 回答