ActionBar没有Show with DrawerLayout FrameLayout Android

时间:2016-10-26 22:40:39

标签: android android-actionbar

我正在使用菜单和框架布局,问题是通过显示第一个活动不向我收取操作栏

感谢您的帮助

click open screenshot

activity_menu.xml

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:fitsSystemWindows="true"
    tools:context="es.expansia.pccom.crm.MenuActivity">

<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
    android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
        android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" 
         app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
android:id="@+id/drawer_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />


</android.support.design.widget.CoordinatorLayout>
 <android.support.design.widget.NavigationView android:id="@+id/nav_view"
    android:layout_width="wrap_content" android:layout_height="match_parent"
    android:layout_gravity="start" android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

activity_actions.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="es.expansia.pccom.crm.ActionsActivity"
android:background="#cccccc">

<com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lvActions"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@android:color/transparent"
        android:dividerHeight="10.0sp"
        >

    </ListView>
</com.baoyz.widget.PullRefreshLayout>

</RelativeLayout>

MenuActivity.java

    public class MenuActivity extends AppCompatActivity
            implements NavigationView.OnNavigationItemSelectedListener  {


        protected DrawerLayout  fullLayout;
        protected FrameLayout frameLayout;

        @Override
        public void setContentView(int layoutResID) {

            fullLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_menu, null);
            frameLayout = (FrameLayout) fullLayout.findViewById(R.id.drawer_frame);

            getLayoutInflater().inflate(layoutResID, frameLayout, true);


            super.setContentView(fullLayout);

            //Your drawer content...

            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);


            this.setSupportActionBar(toolbar);
            ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
            actionBar.show();

            actionBar.setTitle("Toolbar Title");
            actionBar.setSubtitle("Toolbar Subtitle");

            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();

            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);



        }



        @Override
        public void onBackPressed() {
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
            } else {
                super.onBackPressed();
            }
         }

        // @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();

            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }

            return super.onOptionsItemSelected(item);
        }

        @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            // Handle navigation view item clicks here.
            int id = item.getItemId();

            if (id == R.id.nav_camera) {
                // Handle the camera action
            } else if (id == R.id.nav_gallery) {

            } else if (id == R.id.nav_slideshow) {

            } else if (id == R.id.nav_manage) {

            } else if (id == R.id.nav_share) {

            } else if (id == R.id.nav_send) {

            }

            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);
            return true;
        }
    }

ActionsActivity.java

public class ActionsActivity extends MenuActivity {

    PullRefreshLayout layout;

    DatabaseHelper helper = new DatabaseHelper(this);

    ArrayList<HashMap<String, String>> oslist = new ArrayList<HashMap<String, String>>();

    List<Map<String,String>> actionsList = new ArrayList<Map<String,String>>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_actions);

       }
 }

0 个答案:

没有答案