我想在 fragment 中启用主页按钮。早先提出了这个问题,但只是一项 Activity 。
我试过了 ...

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

...但这是行不通的。
这是我的代码:
import com.actionbarsherlock.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.MenuItem;

import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

public class SafanTab extends SherlockFragment {

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.safantab, container, false);
    }

    public OnClickListener onOverClick = new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Over_Safan.class);
            startActivityForResult(myIntent, 0);
        }
    };

    public OnClickListener onProductenClick = new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Over_Safan.class);
            startActivityForResult(myIntent, 0);
        }
    };

    public OnClickListener onTwitterClick = new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Over_Safan.class);
            startActivityForResult(myIntent, 0);
        }
    };

}

如何在SherlockFragment上启用主页按钮?

最佳答案

您是否尝试过将以下代码添加到主要 Activity -那个extends SherlockActivityextends SherlockFragmentActivity的代码中?

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

我认为您无法仅使用getSupportActionBar来实现extends SherlockFragment

关于android - 启用主页按钮ActionbarSherlock,Sherlock fragment ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11617399/

10-10 09:18