Я хочу, чтобы несколько действий имели один и тот же блок навигации, поэтому я создал BaseDrawerActivity
в первом действии: используя framelayout и setContentView (activity_layout_id) Мне удалось получить результат
во втором действии: Я должен использовать setContentView (customView), но элемент панели действий (HomeUpbutton), который был виден в первом действии, не виден
может перекрываться customView?
Я хочу, чтобы элементы панели инструментов были виднычерез просмотр и просмотр, чтобы занять все пространство (также область панели инструментов)
BaseDrawerActivity
public class BaseDrawerActivity extends AppCompatActivity {
protected DrawerLayout fullLayout;
protected FrameLayout frameLayout;
@Override
public void setContentView(int layoutResID) {
fullLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base_drawer, null);
frameLayout= fullLayout.findVi
ewById(R.id.content_frame);
// Setting the content of layout your provided to the act_content frame
getLayoutInflater().inflate(layoutResID, frameLayout, true);
super.setContentView(fullLayout);
setUpToolBar();
}
private void setUpToolBar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
if (actionbar != null) {
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setHomeAsUpIndicator(R.drawable.ic_settings_black_24dp);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// perform whatever you want on back arrow click
// fullLayout.openDrawer(GravityCompat.START);
// return true;
fullLayout.openDrawer(GravityCompat.START);
}
});
}
@Override
public void setContentView(View view) {
// super.setContentView(view);
fullLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base_drawer, null);
frameLayout= fullLayout.findViewById(R.id.content_frame);
frameLayout.addView(view);
// getLayoutInflater().inflate(layoutResID, frameLayout, true);
super.setContentView(fullLayout);
setUpToolBar();
}
}
activity_base_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</FrameLayout>
<ScrollView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:gravity="bottom|center">
<LinearLayout
android:layout_width="540dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
android:paddingTop="30dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text 1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="@drawable/try1" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
CustomView
public class CustomView extends View {
Bitmap background ;
Rect rect;
int dWidth,dHeight;
public CustomView(Context context) {
super(context);
background = BitmapFactory.decodeResource(getResources(),R.drawable.background);
Display display = ((Activity)getContext()).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
dWidth = size.x;
dHeight = size.y;
rect = new Rect(0,0,dWidth,dHeight);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(background,null,rect,null);
}
}
.
edit
в activity_base_drawer.xml
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<FrameLayout
android:id="@+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
>
</FrameLayout>
</LinearLayout>
в BaseDrawerActivity
@Override
public void setContentView(View view) {
// super.setContentView(view);
fullLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base_drawer, null);
linearLayout = fullLayout.findViewById(R.id.content_frame);
framelayout=linearLayout.findViewById(R.id.framelayout);
framelayout.addView(view);
// getLayoutInflater().inflate(layoutResID, linearLayout, true);
super.setContentView(fullLayout);
setUpToolBar();
}