修改NavigationBar后横屏崩溃

来源:互联网 发布:淘宝买k粉暗语 编辑:程序博客网 时间:2024/06/03 17:45

修改SystemUI并编译参照这篇文章:
http://blog.csdn.net/zhonglunshun/article/details/70256734

因为公司做的系统需要横屏,因此当我切换到横屏的时候一直报空指针,大概意思就是我加进去的哪几个button找不到。

开始的时候我以为是自己的代码写错了,但是检查好几遍也没有错误啊,上网也很少有这样的错误出现,无奈只能从报错的源头入手

然后我检查竖屏切换到横屏的时候经历了什么,看啊看啊,发现了这一段:

...    @Override    public void onFinishInflate() {        mRotatedViews[Surface.ROTATION_0] =        mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0);        mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90);        mRotatedViews[Surface.ROTATION_270] = mRotatedViews[Surface.ROTATION_90];        mCurrentView = mRotatedViews[Surface.ROTATION_0];        getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);        updateRTLOrder();    }    public boolean isVertical() {        return mVertical;    }    public void reorient() {        final int rot = mDisplay.getRotation();        for (int i=0; i<4; i++) {            mRotatedViews[i].setVisibility(View.GONE);        }        mCurrentView = mRotatedViews[rot];        mCurrentView.setVisibility(View.VISIBLE);        getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);        mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone);        // force the low profile & disabled states into compliance        mBarTransitions.init(mVertical);        setDisabledFlags(mDisabledFlags, true /* force */);        setMenuVisibility(mShowMenu, true /* force */);        if (DEBUG) {            Log.d(TAG, "reorient(): rot=" + mDisplay.getRotation());        }        // swap to x coordinate if orientation is not in vertical        if (mDelegateHelper != null) {            mDelegateHelper.setSwapXY(mVertical);        }        updateTaskSwitchHelper();        setNavigationIconHints(mNavigationIconHints, true);    }...

看代码说的是切换角度的时候,findViewById(R.id.rot90) ,我就找这个rot90和rot0是个什么鬼,果不其然在布局文件里面改了,rot0节点下我修改了我的代码,但是rot90没有修改。问题难道出现在这里?

于是我把rot90节点下也加上我添加的布局:

 <View                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:visibility="invisible" />             <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/voiceAssist"               android:layout_width="match_parent"                android:layout_height="80dp"                android:layout_weight="0"                android:contentDescription="@string/accessibility_back"                android:scaleType="center"                android:src="@drawable/rc_statuebar_voiceassist_selector"                 />            <View                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:visibility="invisible" />            <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/videoCapture"                android:layout_width="match_parent"                android:layout_height="80dp"                android:layout_weight="0"                android:contentDescription="@string/accessibility_back"                android:scaleType="center"                android:src="@drawable/ic_sysbar_video_off" />

然后重新编译,推送到设备,重启,横屏。

呀!!没崩溃了

真棒!!!

原创粉丝点击