我正在为我的应用程序使用 Action Bar Sherlock 片段。我需要从活动中去片段。但是当我使用此代码进入片段时,滑动菜单不起作用。
活动代码
Intent notificationIntent = new Intent(context,FragmentOpenActivity.class);
FragmentOpenActivity 就像
public class FragmentOpenActivity extends SherlockFragmentActivity {
private Bundle i_fragment;
private String messages = null;
private String coupons = null;
private String yo = null;
private String invitation = null;
private String loyalty = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
// .add(android.R.id.content, new MessagesFragment()).commit();
i_fragment = getIntent().getExtras();
if (i_fragment == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new ProfileEditorFragment())
.commit();
} else {
messages = i_fragment.getString("Message");
coupons = i_fragment.getString("Coupon");
}
if (messages != null && messages.equalsIgnoreCase("Message")) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new MessagesFragment())
.commit();
} else if (coupons != null && coupons.equalsIgnoreCase("Coupon")) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new CouponsFragment())
.commit();
} else {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new ProfileEditorFragment())
.commit();
}
}
}
/**
* @return Displaying Action Bar Button with Image
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
/**
* @return Click Events for Action Bar Buttons
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
startActivity(new Intent(this, FragmentChangeActivity.class));
break;
}
return true;
}
/**
* @return Handling Back button
*/
public void onBackPressed() {
startActivity(new Intent(this, FragmentChangeActivity.class));
finish();
}
}
Please refer the following code for fragment
public class CouponsFragment extends SherlockFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getSherlockActivity().getSupportActionBar().setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM);
getSherlockActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(
true);
return inflater.inflate(R.layout.listview_refreshable, null);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public void onStart() {
super.onStart();
}
}
通常滑动菜单可以完美运行,但是当我来自FragmentOpenActivity
它时没有响应。请尝试为我找到解决方案