所以我找到了一个解决办法,通过设置homeAsUpIndicator xml值来在整个应用程序中设置多个不同的主页按钮:
<item name="android:homeAsUpIndicator">@null</item>
<item name="homeAsUpIndicator">@null</item>
使用setLogo(...);
在代码中设置徽标我的问题是徽标仅在某些情况下显示,这是一个不起作用的徽标:
public class DiscountActivity extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_discount);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setLogo(R.drawable.back_x);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
View actionView = getLayoutInflater().inflate(R.layout.nextlist_bar, null);
TextView title = (TextView) actionView.findViewById(R.id.nextbar_title);
title.setText(getIntent().getStringExtra("Establishment"));
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
actionBar.setCustomView(actionView, params);
actionBar.setIcon(new ColorDrawable(Color.TRANSPARENT));
}
}
工作情况:
public class NextListActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_next_list);
con = NextListActivity.this;
layout_MainMenu = (FrameLayout) findViewById( R.id.dimmer);
layout_MainMenu.getForeground().setAlpha( 0);
SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
Type type = new TypeToken<List<String>>(){}.getType();
favorites = gson.fromJson(appSharedPrefs.getString("Favorites", ""), type);
if (favorites == null) favorites = new ArrayList<String>();
mPager = (NonScrollablePager) findViewById(R.id.pager);
mPagerAdapter = new MyAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
curLoc = getIntent().getParcelableExtra("CurLoc");
clickedItem = new ViewHolder("", "", "", "", R.drawable.bandus, "", "");
nextTitle = getIntent().getStringExtra("NextTitle");
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setLogo(R.drawable.back_arrow);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(true);
actionView = getLayoutInflater().inflate(R.layout.nextlist_bar, null);
TextView title = (TextView) actionView.findViewById(R.id.nextbar_title);
title.setText(nextTitle);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
actionBar.setCustomView(actionView, params);
actionBar.setIcon(new ColorDrawable(Color.TRANSPARENT));
}
}
任何人都可以帮我理解我的问题吗? :)