我正在构建具有购物车菜单项且所有产品都按片段打开的android购物应用,我想在产品片段和其他片段上设置MainActivity菜单项。
因此,用户很容易从产品视图片段中打开购物车。代码如下
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.product_view_fragment, null);
setHasOptionsMenu(true);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
getActivity().invalidateOptionsMenu();
toolbar = (Toolbar)view.findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().onBackPressed();
}
});
this.context = getContext();
String id=getArguments().getString("message");
//String size=getArguments().getString("size");
viewPager = (ViewPager)view.findViewById(R.id.viewPager);
SessionManager sessionManager = new SessionManager(getContext());
email = sessionManager.getUserDetails().get("id");
sliderDotspanel = (LinearLayout)view.findViewById(R.id.SliderDots);
GetOneProduct(id);
return view;
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:segmentedgroup="http://schemas.android.com/tools"
android:orientation="vertical"
android:clickable="true"
android:background="@color/colorWhite"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@android:style/Animation.Activity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextColor="@color/Black" />
</android.support.design.widget.AppBarLayout>
Blockquote
答案 0 :(得分:0)
我假设您使用单一活动方法。 然后,您的活动应在其布局中包含“工具栏”,如下所示。
@Bean
@Profile("export")
public AnnotationGatewayProxyFactoryBean exportingOutboundGateway() {
return new AnnotationGatewayProxyFactoryBean(ExportingOutboundGateway.class);
}
...
public interface ExportingOutboundGateway {
@Gateway(requestChannel = "exportChannel")
void send(String request);
}
然后根据需要在活动中设置工具栏。