2013-12-15 7 views
0

나는이 질문이 전에 (2 다른 유사한 발견) 물었다는 것을 알고 있지만 그들은 시나리오의 측면을 해결하지 못했습니다!안드로이드 내비게이션 서랍 추상화

public class BaseActivity extends ActionBarActivity { 

    // Implemeted the Actionbar and navigation drawer here! 
    // and it containts onCreate method and setContentView 
} 

BaseActivity의 XML :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/base_nav_drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
    </LinearLayout> 
    <ListView 
      android:id="@+id/base_left_drawer" 
      android:layout_width="320dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#dddddd"/> 
    <ListView 
      android:id="@+id/base_right_drawer" 
      android:layout_width="320dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="end" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#dddddd"/> 
</android.support.v4.widget.DrawerLayout> 

는 다음에서 내 주요 클래스/활동을 확장 :

public class Main extends BaseActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
     } 
    } 

SO 여기

는 시나리오이다,이 같은 클래스를 생성 주요 활동 XML :

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:id="@+id/stream_new_layout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="hi dude"/>  
</LinearLayout> 

그래서 내 활동에 setContectView(R.layout.main)을 사용하려고하면 Actionbar와 Navigation 서랍을 볼 수 있습니다.이 활동과 관련된 XML 레이아웃을 사용하려면 탐색 서랍에 아무 것도 표시되지 않습니다. 더 이상; 나는 메인 활동에 onCreatesetContectView이 있기 때문에 내가 확장 한 BaseActivity에서 같은 문장을 덮어 쓴다고 생각한다. 이 모든 솔루션? 당신은 당신의 레이아웃 설정의 나머지 부분을 수행하기 위해 MainActivity의 서랍과 setContentView()을 설정하기 위해 BaseActivitysetContentView()을 사용하고 있습니다 :

+0

2 가지 활동에 대한 onCreate 메소드의 전체 구현을 게시 할 수 있습니까? 나는 ActionBar가 완전히 사라지는 것을 상상할 수 없다 ... – FWeigl

+0

나의 나쁜! 작업 표시 줄이 나타납니다. 탐색 서랍 만 작동하지 않거나 표시되지 않습니다. – kevoroid

답변

1

은 내가 바로 당신을 이해 희망? 그런 경우 : 그렇게 작동하지 않습니다. 두 번째로 setContentView()을하면 이전 레이아웃을 대체하고 더 이상 서랍이 없습니다. MainActivity에서 setContentView()에 사용하는 레이아웃의 서랍이 있어야합니다. 또한 아들은 setContentView() 두 번 사용하지 않습니다. 처음에는 쓸모가 없습니다.

+0

그래서, 내 BaseActivity에서 "setContentView()"를 사용해서는 안된다. 그리고 위에 게시 한 BaseActivity XML을 기본 활동의 XML 레이아웃으로 사용해야한다. – kevoroid

+0

예, 시도해보십시오. 서랍을 갖고 싶다면 MainActivity에서 사용하는 레이아웃에 하나 있어야합니다. – FWeigl

관련 문제