AccelerateInterpolator同步状态

时间:2018-06-09 17:04:19

标签: android android-layout

在Android开发者世界中我是新手并需要帮助,我需要按任何按钮上的按下工具栏的访问状态,按下工具栏后会看到,我要关闭它或隐藏按钮按下打开视图,请指教

2 个答案:

答案 0 :(得分:0)

我的代码:

@Override
public View onCreateView(
        @NonNull LayoutInflater inflater, ViewGroup container, Bundle 
savedInstanceState) {
    // Inflate the layout for this fragment with the ProductGrid theme
    View view = inflater.inflate(R.layout.product_grid_fragment, container, false);
    // Set up the tool bar
    setUpToolbar(view);
    esas_btn = (Button)view.findViewById(R.id.esas_btn);
    mq = (Button)view.findViewById(R.id.mq_btn);
    sur = (Button)view.findViewById(R.id.sure_btn);
    da = (Button)view.findViewById(R.id.dua_btn);
    esas_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Begin the transaction
                setFragment(new EsasFragment());
        }
    });        mq.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Begin the transaction
                setFragment(new MQMaterialFragment());
        }
    });        sur.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Begin the transaction
                setFragment(new SurelerFragment());
        }
    });        da.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Begin the transaction
                setFragment(new DualarFragment());
        }
    });


    return view;
}

private void setFragment(Fragment fragment){
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, fragment, "visible_fragment");
    ft.addToBackStack(null);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
   ft.commit();        toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.shr_branded_menu));
}

private void setUpToolbar(View view) {
    toolbar = view.findViewById(R.id.app_bar);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        activity.setSupportActionBar(toolbar);
    }

    toolbar.setNavigationOnClickListener(new NavigationIconClickListener(
            getContext(),
            view.findViewById(R.id.product_grid),
            new AccelerateInterpolator(),
            getContext().getResources().getDrawable(R.drawable.bran_menu), 
    getContext().getResources().getDrawable(R.drawable.close_menu))); // Menu close icon
}

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:context=".SelectionGridFragment">

<LinearLayout
    style="@style/Widget.Shrine.Backdrop"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingTop="88dp">

    <include layout="@layout/shr_backdrop" />
</LinearLayout>


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/app_bar"
        style="@style/Widget.Shrine.Toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:paddingStart="12dp"
        android:paddingLeft="12dp"
        android:paddingEnd="12dp"
        android:paddingRight="12dp"
        app:contentInsetStart="0dp"
        app:navigationIcon="@drawable/shr_branded_menu"
        app:title="@string/app_name" />
</android.support.design.widget.AppBarLayout>


<LinearLayout
    android:id="@+id/product_grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="56dp"
    android:background="@color/productGridBackgroundColor"
    android:elevation="8dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_marginLeft="30dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>