Browse Source

Make system bars completely transparent

feature_fragments
vanitasvitae 5 years ago
parent
commit
09241253c8
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
  1. 20
      app/src/main/java/de/trac/spherical/MainActivity.java
  2. 34
      app/src/main/res/layout/activity_main.xml
  3. 16
      app/src/main/res/values-v21/styles.xml

20
app/src/main/java/de/trac/spherical/MainActivity.java

@ -3,6 +3,7 @@ package de.trac.spherical;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
@ -15,7 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.io.FileNotFoundException;
@ -38,7 +42,6 @@ public class MainActivity extends AppCompatActivity {
private Renderer renderer;
private FloatingActionButton fab;
private Toolbar toolbar;
private AppBarLayout appBarLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -49,10 +52,9 @@ public class MainActivity extends AppCompatActivity {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
appBarLayout = (AppBarLayout) findViewById(R.id.lay_toolbar);
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
lp.topMargin += getStatusBarHeight();
appBarLayout.bringToFront();
toolbar.bringToFront();
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
@ -62,6 +64,11 @@ public class MainActivity extends AppCompatActivity {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
// Initialize renderer and setup surface view.
LinearLayout container = (LinearLayout) findViewById(R.id.container);
surfaceView = new SphereSurfaceView(this);
@ -102,10 +109,10 @@ public class MainActivity extends AppCompatActivity {
private void displayUI(boolean display) {
if (display) {
fab.show();
appBarLayout.setExpanded(true, true);
toolbar.setVisibility(View.VISIBLE);
} else {
fab.setVisibility(View.INVISIBLE);
appBarLayout.setExpanded(false, true);
toolbar.setVisibility(View.GONE);
}
}
@ -223,6 +230,7 @@ public class MainActivity extends AppCompatActivity {
*/
private void displayFlatImage(InputStream inputStream) {
Log.d(TAG, "Display Flat Image!");
displayPhotoSphere(inputStream, new PhotoSphereMetadata());
}
public int getStatusBarHeight() {

34
app/src/main/res/layout/activity_main.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<RelativeLayout
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"
@ -9,28 +9,18 @@
android:fitsSystemWindows="false"
tools:context="de.trac.spherical.MainActivity">
<android.support.design.widget.AppBarLayout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lay_toolbar"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:theme="@style/AppTheme.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat" />
</android.support.design.widget.AppBarLayout>
android:layout_alignParentTop="true"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:theme="@style/AppTheme.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat" />
<LinearLayout
android:id="@+id/container"
@ -45,7 +35,9 @@
android:id="@+id/fab"
android:src="@drawable/ic_explore_white_48px"
app:fabSize="mini"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="64dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
@ -54,4 +46,4 @@
app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

16
app/src/main/res/values-v21/styles.xml

@ -1,2 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionBarOverlay">false</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:fitsSystemWindows">false</item>
</style>
</resources>
Loading…
Cancel
Save