Reputation: 363
I am designing a layout for my app and i used a FrameLayout
which is fairly simple,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_slide"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000000">
</FrameLayout>
This is my activity code,
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;
import java.util.ArrayList;
import java.util.Arrays;
import codopoliz.com.hscomply.Fragments.SlidingMenuFragment;
import codopoliz.com.hscomply.Models.MenuModel;
import codopoliz.com.hscomply.R;
public class MainActivity extends SlidingActivity {
private ArrayList<String> menuList;
private MenuModel[] menuItems;
private View mCustomView;
private TextView title;
private SlidingMenu sm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sliding);
setStatusBarColorInMain();
setBehindView();
setupDrawer();
final ActionBar actionBar = getSupportActionBar();
LayoutInflater mInflater = LayoutInflater.from(this);
mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setElevation(0);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setCustomView(mCustomView, layoutParams);
actionBar.setDisplayShowCustomEnabled(true);
Toolbar parent = (Toolbar) mCustomView.getParent();
parent.setContentInsetsAbsolute(0, 0);
title = (TextView) mCustomView.findViewById(R.id.header_title);
ImageView menubtn = (ImageView) mCustomView.findViewById(R.id.menu_Button);
menubtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sm.toggle();
}
});
menuList = getIntent().getStringArrayListExtra("menu");
Object[] arrayObject = (Object[]) getIntent().getSerializableExtra("menuItems");
menuItems = Arrays.copyOf(arrayObject , arrayObject.length, MenuModel[].class);
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
}
private void setBehindView() {
setBehindContentView(R.layout.menu_slide);
transactionFragments(SlidingMenuFragment.newInstance(), false, R.id.menu_slide, false, "MainFragment");
}
public void setActionBarTitle(String actionBarTitle) {
title.setText(actionBarTitle);
}
public void transactionFragments(Fragment fragment, boolean backStackTag, int viewResource, boolean toogleOff, String fragmentTag) {
final Fragment selectedFrag = getSupportFragmentManager().findFragmentByTag(fragmentTag);
SlidingMenuFragment fragmentMenu = (SlidingMenuFragment) getSupportFragmentManager().findFragmentByTag("MainFragment");
if (selectedFrag != null && selectedFrag.isVisible()) {
toggle();
return;
}
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(viewResource, fragment, fragmentTag);
if (backStackTag)
ft.addToBackStack(null);
ft.commit();
if (!toogleOff) {
toggle();
}
}
private void setupDrawer() {
sm = getSlidingMenu();
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
// case android.R.id.home:
// mSlidingMenu.toggle();
// return true;
// default:
// return super.onOptionsItemSelected(item);
// }
// }
//
// @Override
// public void onBackPressed() {
// if (mSlidingMenu.isMenuShowing()) {
// mSlidingMenu.toggle();
// } else {
// super.onBackPressed();
// }
// }
public ArrayList<String> getMenuListData() {
return menuList;
}
public MenuModel[] getMenuItemsData() {
return menuItems;
}
public void setStatusBarColorInMain(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(this, R.color.color_status_in_main));
}
}
}
And this is my Style,
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!--<item name="colorPrimary">@color/colorPrimary</item>-->
<!--<item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<!--<item name="colorAccent">@color/colorAccent</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppThemeSuper" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentOverlay">@null</item>
</style>
<!--For progress dialog-->
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/colorPrimaryDark</item>
<item name="android:textColorPrimary">@color/menu_white</item>
<item name="android:background">@color/menu_white</item>
</style>
</resources>
Now i tested in multiples devices in most of them the design works fine. It is like this,
But in some devices there is a white empty area appearing at bottom of the screen. Like this,
I also checked by rotating the device and the white area appears at right side of the screen.
How can i remove this empty space from the screen. Please any help would be appreciated..
Upvotes: 0
Views: 534
Reputation: 147
add this flag after setting status bar color
addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
It worked for me.
Upvotes: 1