Android工具栏被推到顶部状态栏的后面

Android工具栏被推到顶部状态栏的后面,第1张

概述我最近将手机更新为Android5.0.2,现在正在开发的应用程序出现了一个工具栏问题.工具栏被向上推,并被最顶部状态栏部分隐藏.什么会导致此问题?这是活动的代码,具有用于处理工具栏的布局publicclassLeftMenusActivityextendsActionBarActivityimplementsFeedFragment.OnF

我最近将手机更新为Android 5.0.2,现在正在开发的应用程序出现了一个工具栏问题.工具栏被向上推,并被最顶部的状态栏部分隐藏.

什么会导致此问题?

这是活动的代码,具有用于处理工具栏的布局

public class leftMenusActivity extends ActionBaractivity implements FeedFragment.OnFragmentInteractionListener, UserFragment.OnFragmentInteractionListener,        SettingsFragment.OnFragmentInteractionListener, CreateFragment.OnFragmentInteractionListener, TimersFragment.OnFragmentInteractionListener,        CalendarFragment.OnFragmentInteractionListener, DetailFragment.OnFragmentInteractionListener, SingleWorkoutItemDetailFragment.OnFragmentInteractionListener {    public static final String left_MENU_OPTION = "com.modup.app.leftMenusActivity";    public static final String left_MENU_OPTION_1 = "left Menu Option 1";    public static final String left_MENU_OPTION_2 = "left Menu Option 2";    private ListVIEw mDrawerList;    private List<DrawerItem> mDrawerItems;    private DrawerLayout mDrawerLayout;    private ActionbarDrawerToggle mDrawerToggle;    private CharSequence mDrawerTitle;    private CharSequence mTitle;    private SingleWorkout currentSingleWorkoutObject;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_left_menus);        setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);        Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.toolbar);        setSupportActionbar(toolbar);        mDrawerLayout = (DrawerLayout) findVIEwByID(R.ID.drawer_layout);        mTitle = mDrawerTitle = getTitle();        mDrawerLayout = (DrawerLayout) findVIEwByID(R.ID.drawer_layout);        mDrawerList = (ListVIEw) findVIEwByID(R.ID.List_vIEw);        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);        prepareNavigationDrawerItems();        setAdapter();        //mDrawerList.setAdapter(new DrawerAdapter(this, mDrawerItems));        mDrawerList.setonItemClickListener(new DrawerItemClickListener());        mDrawerToggle = new ActionbarDrawerToggle(this, mDrawerLayout, toolbar,                R.string.drawer_open,                R.string.drawer_close) {            public voID onDrawerClosed(VIEw vIEw) {                getSupportActionbar().setTitle(mTitle);                invalIDateOptionsMenu();            }            public voID onDrawerOpened(VIEw drawerVIEw) {                getSupportActionbar().setTitle(mDrawerTitle);                invalIDateOptionsMenu();            }        };        mDrawerLayout.setDrawerListener(mDrawerToggle);        if (savedInstanceState == null) {            mDrawerLayout.closeDrawer(mDrawerList);            FragmentManager fragmentManager = getFragmentManager();            Fragment mFragment = new FeedFragment();            fragmentManager.beginTransaction().replace(R.ID.content_frame, mFragment).commit();        }    }    private voID setAdapter() {        String option = left_MENU_OPTION_1;        Bundle extras = getIntent().getExtras();        if (extras != null && extras.containsKey(left_MENU_OPTION)) {            option = extras.getString(left_MENU_OPTION, left_MENU_OPTION_1);        }        boolean isFirstType = true;        VIEw headerVIEw = null;        if (option.equals(left_MENU_OPTION_1)) {            headerVIEw = prepareheaderVIEw(R.layout.header_navigation_drawer_1,                    "http://pengaja.com/uiapptemplate/avatars/0.jpg",                    "dev@csform.com");        } else if (option.equals(left_MENU_OPTION_2)) {            headerVIEw = prepareheaderVIEw(R.layout.header_navigation_drawer_2,                    "http://pengaja.com/uiapptemplate/avatars/0.jpg",                    "dev@csform.com");            isFirstType = false;        }        BaseAdapter adapter = new DrawerAdapter(this, mDrawerItems, isFirstType);        mDrawerList.addheaderVIEw(headerVIEw);//Add header before adapter (for pre-KitKat)        mDrawerList.setAdapter(adapter);    }    private VIEw prepareheaderVIEw(int layoutRes, String url, String email) {        VIEw headerVIEw = getLayoutInflater().inflate(layoutRes, mDrawerList, false);        ImageVIEw iv = (ImageVIEw) headerVIEw.findVIEwByID(R.ID.imageVIEwProfilePic);        TextVIEw tv = (TextVIEw) headerVIEw.findVIEwByID(R.ID.email);        ImageUtil.displayRoundImage(iv, url, null);        tv.setText(ParseUser.getCurrentUser().getEmail());        return headerVIEw;    }    private voID prepareNavigationDrawerItems() {        mDrawerItems = new ArrayList<DrawerItem>();        mDrawerItems.add(                new DrawerItem(                        R.drawable.Feed,                        R.string.drawer_Title_Feed,                        DrawerItem.DRAWER_ITEM_TAG_Feed));        mDrawerItems.add(                new DrawerItem(                        R.drawable.user,                        R.string.drawer_Title_user,                        DrawerItem.DRAWER_ITEM_TAG_USER));        mDrawerItems.add(                new DrawerItem(                        R.drawable.stopwatch,                        R.string.drawer_Title_timers,                        DrawerItem.DRAWER_ITEM_TAG_TIMERS));        mDrawerItems.add(                new DrawerItem(                        R.drawable.calendar,                        R.string.drawer_Title_calendar,                        DrawerItem.DRAWER_ITEM_TAG_CALENDAR));    }    @OverrIDe    public boolean onCreateOptionsMenu(Menu menu) {        MenuInflater inflater = getMenuInflater();        inflater.inflate(R.menu.main, menu);        return super.onCreateOptionsMenu(menu);    }    @OverrIDe    public boolean onPrepareOptionsMenu(Menu menu) {        return super.onPrepareOptionsMenu(menu);    }    @OverrIDe    public boolean onoptionsItemSelected(MenuItem item) {        if (mDrawerToggle.onoptionsItemSelected(item)) {            return true;        }        return super.onoptionsItemSelected(item);    }    @OverrIDe    public voID onFragmentInteraction(Uri uri) {    }    private class DrawerItemClickListener implements            ListVIEw.OnItemClickListener {        @OverrIDe        public voID onItemClick(AdapterVIEw<?> parent, VIEw vIEw, int position,                                long ID) {            selectItem(position/*, mDrawerItems.get(position - 1).getTag()*/);        }    }    //set up fragment switching here    private voID selectItem(int position/*, int drawerTag*/) {        // minus 1 because we have header that has 0 position        FragmentManager fragmentManager = getFragmentManager();        Fragment mFragment;        if (position < 1) { //because we have header, we skip clicking on it            return;        }        switch (position) {            case 1:                mFragment = new FeedFragment();                fragmentManager.beginTransaction().replace(R.ID.content_frame, mFragment).commit();                break;            case 2:                mFragment = new UserFragment();                fragmentManager.beginTransaction().replace(R.ID.content_frame, mFragment).commit();                break;            case 3:                mFragment = new TimersFragment();                fragmentManager.beginTransaction().replace(R.ID.content_frame, mFragment).commit();                break;            case 4:                mFragment = new CalendarFragment();                fragmentManager.beginTransaction().replace(R.ID.content_frame, mFragment).commit();                break;        }/*      String drawerTitle = getString(mDrawerItems.get(position - 1).getTitle());        Toast.makeText(this, "You selected " + drawerTitle + " at position: " + position, Toast.LENGTH_SHORT).show();*/        mDrawerList.setItemChecked(position, true);        setTitle(mDrawerItems.get(position - 1).getTitle());        mDrawerLayout.closeDrawer(mDrawerList);    }    @OverrIDe    public voID setTitle(int TitleID) {        setTitle(getString(TitleID));    }    @OverrIDe    public voID setTitle(CharSequence Title) {        mTitle = Title;        getSupportActionbar().setTitle(mTitle);    }    @OverrIDe    protected voID onPostCreate(Bundle savedInstanceState) {        super.onPostCreate(savedInstanceState);        mDrawerToggle.syncState();    }    @OverrIDe    public voID onConfigurationChanged(Configuration newConfig) {        super.onConfigurationChanged(newConfig);        mDrawerToggle.onConfigurationChanged(newConfig);    }}

XML布局

<?xml version="1.0"?><linearLayout androID:orIEntation="vertical" androID:layout_height="match_parent" androID:layout_wIDth="match_parent"              xmlns:androID="http://schemas.androID.com/apk/res/androID">    <include layout="@layout/toolbar"/>    <androID.support.v4.Widget.DrawerLayout androID:layout_height="match_parent" androID:layout_wIDth="match_parent"                                            xmlns:androID="http://schemas.androID.com/apk/res/androID"                                            androID:fitsSystemwindows="true"                                            androID:ID="@+ID/drawer_layout">        <FrameLayout androID:layout_height="match_parent" androID:layout_wIDth="match_parent"                     androID:background="@color/material_grey_200"                     androID:ID="@+ID/content_frame"/>        <include androID:layout_height="match_parent" androID:layout_wIDth="@dimen/drawer_wIDth"                 layout="@layout/List_vIEw" androID:layout_gravity="start"/>    </androID.support.v4.Widget.DrawerLayout></linearLayout>

工具栏的XML布局

<?xml version="1.0" enCoding="utf-8"?>    <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="56dp"                                       androID:elevation="4dp"                                       androID:background="@color/primary_blue"                                       app:popuptheme="@style/theme.AppCompat.light.DarkActionbar"                                       app:theme="@style/Apptheme.Title"/>

解决方法:

删除androID:fitsSystemwindows =“ true”或将工具栏移动到DrawerLayout的第一个元素内(添加LL,因为DrawerLayout可以在其​​中使用2个视图).

总结

以上是内存溢出为你收集整理的Android工具栏被推到顶部状态栏的后面全部内容,希望文章能够帮你解决Android工具栏被推到顶部状态栏的后面所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1088905.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存