2016-02-14 4 views
0

Я работаю над наличием единого навигационного ящика для всех видов деятельности, поэтому я решил добавить его в BaseActivity, а затем наследовать его в других действиях, где мне нужен ящик для навигации, и я действительно добился успеха в том, что рабочий ящик навигации работает, но по какой-то причине панель инструментов не отображается в дочерних действиях, которые наследуют BaseActivity. Я пробовал много вещей и проверял много вопросов о переполнении стека, но я не мог понять, в чем проблема ,Панель инструментов не отображается в дочерней активности

Вот код: Файл макета

activity_base.xml

<android.support.v4.widget.DrawerLayout 

xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/DrawerLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:elevation="7dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <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:popupTheme="@style/AppTheme.PopupOverlay" /> 
    </android.support.design.widget.AppBarLayout> 
</LinearLayout> 


<android.support.v7.widget.RecyclerView 
    android:id="@+id/RecyclerView" 
    android:layout_width="320dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left" 

    android:background="#ffffff" 
    android:scrollbars="vertical"> 

</android.support.v7.widget.RecyclerView> 

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


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

Я использую этот файл макета здесь в OnCreate из BaseActivity:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_base); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);   mRecyclerView.setHasFixedSize(true);       // Letting the system know that the list objects are of fixed size 

    mAdapter = new NavigationFragmentAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE);  // Creating the Adapter of MyAdapter class(which we are going to see in a bit) 
    // And passing the titles,icons,header view name, header view email, 
    // and header view profile picture 

    mRecyclerView.setAdapter(mAdapter);        // Setting the adapter to RecyclerView 

    mLayoutManager = new LinearLayoutManager(this);     // Creating a layout Manager 

    mRecyclerView.setLayoutManager(mLayoutManager);     // Setting the layout Manager 


    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);  // Drawer object Assigned to the view 
    mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.drawer_open,R.string.drawer_close){ 

     @Override 
     public void onDrawerOpened(View drawerView) { 
      super.onDrawerOpened(drawerView); 
      // code here will execute once the drawer is opened(As I dont want anything happened whe drawer is 
      // open I am not going to put anything here) 
     } 

     @Override 
     public void onDrawerClosed(View drawerView) { 
      super.onDrawerClosed(drawerView); 
      // Code here will execute once drawer is closed 
     } 



    }; // Drawer Toggle Object Made 
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle 
    mDrawerToggle.syncState();    // Finally we set the drawer toggle sync State 

} 

Тогда я наследую эту деятельность в других ребенок деятельность (HomeActivity):

public class HomeActivity extends BaseActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.activity_home); 
    ViewGroup content = (ViewGroup) findViewById(R.id.content_frame); 
    getLayoutInflater().inflate(R.layout.activity_home, content, true); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
} 

XML-файл для HomeActivity:

<LinearLayout 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:id="@+id/home_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="app.packman.activity.HomeActivity"> 

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/home_tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <include layout="@layout/content_home" /> 
<!-- other content of activity--> 
</android.support.design.widget.CoordinatorLayout> 

скриншот выход HomeActivity который не имеет панели инструментов (что является проблемой я столкнулся): enter image description here

Любые предложения окажут большую помощь

ответ

0

Вы можете попробовать дд

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

в вашем FrameLayout

Смежные вопросы