Dynamical navigation drawer size
This commit is contained in:
parent
23792f4067
commit
5a4cb23877
|
@ -5,10 +5,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -96,6 +99,7 @@ public class MainActivity extends CastEnabledActivity {
|
|||
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
navDrawer = findViewById(R.id.navDrawerFragment);
|
||||
setNavDrawerSize();
|
||||
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
fm.addOnBackStackChangedListener(() -> {
|
||||
|
@ -323,6 +327,24 @@ public class MainActivity extends CastEnabledActivity {
|
|||
if (drawerToggle != null) { // Tablet layout does not have a drawer
|
||||
drawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
setNavDrawerSize();
|
||||
}
|
||||
|
||||
private void setNavDrawerSize() {
|
||||
if (drawerToggle == null) { // Tablet layout does not have a drawer
|
||||
return;
|
||||
}
|
||||
float screenPercent = getResources().getInteger(R.integer.nav_drawer_screen_size_percent) * 0.01f;
|
||||
int width = (int) (getScreenWidth() * screenPercent);
|
||||
int maxWidth = (int) getResources().getDimension(R.dimen.nav_drawer_max_screen_size);
|
||||
|
||||
navDrawer.getLayoutParams().width = Math.min(width, maxWidth);
|
||||
}
|
||||
|
||||
private int getScreenWidth() {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
return displayMetrics.widthPixels;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
android:id="@+id/navDrawerFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_gravity="start"
|
||||
android:orientation="vertical" />
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="subscriptions_default_num_of_columns">3</integer>
|
||||
<integer name="nav_drawer_screen_size_percent">80</integer>
|
||||
</resources>
|
|
@ -38,4 +38,6 @@
|
|||
<dimen name="media_router_controller_playback_control_start_padding">24dp</dimen>
|
||||
<dimen name="media_router_controller_bottom_margin">8dp</dimen>
|
||||
|
||||
<dimen name="nav_drawer_max_screen_size">480dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue