나는이 질문이 전에 (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 레이아웃을 사용하려면 탐색 서랍에 아무 것도 표시되지 않습니다. 더 이상; 나는 메인 활동에 onCreate
과 setContectView
이 있기 때문에 내가 확장 한 BaseActivity에서 같은 문장을 덮어 쓴다고 생각한다. 이 모든 솔루션? 당신은 당신의 레이아웃 설정의 나머지 부분을 수행하기 위해 MainActivity
의 서랍과 setContentView()
을 설정하기 위해 BaseActivity
에 setContentView()
을 사용하고 있습니다 :
2 가지 활동에 대한 onCreate 메소드의 전체 구현을 게시 할 수 있습니까? 나는 ActionBar가 완전히 사라지는 것을 상상할 수 없다 ... – FWeigl
나의 나쁜! 작업 표시 줄이 나타납니다. 탐색 서랍 만 작동하지 않거나 표시되지 않습니다. – kevoroid