这两天由于一个客户的要求,将MID竖屏时候的状态条上的音量键去掉。所以尝试修改了一下,成功了,分享一下经验。
先看一下修改后的效果图,如下所示 。
横屏的时候:有音量加减键
竖屏的时候:音量加减键被去掉了
然后来说一说我的解决思路。
首先我查看了\mx0831-0525\frameworks\base\packages\SystemUI\res\layout\system_bar.xml文件
<?xml version="1.0" encoding="utf-8"?>
<!--
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<!-- TabletStatusBarView extends FrameLayout -->
<com.android.systemui.statusbar.tablet.TabletStatusBarView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:background="@drawable/system_bar_background"
>
<FrameLayout
android:id="@+id/bar_contents_holder"
android:layout_width="match_parent"
android:layout_height="@*android:dimen/system_bar_height"
android:layout_gravity="bottom"
>
<RelativeLayout
android:id="@+id/bar_contents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
>
<!-- notification icons & panel access -->
<include layout="@layout/system_bar_notification_area"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginTop="1dp"
/>
<!-- navigation controls -->
<LinearLayout
android:id="@+id/navigationArea"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:clipChildren="false"
android:clipToPadding="false"
>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_back"
systemui:keyCode="4"
android:contentDescription="@string/accessibility_back"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_home"
systemui:keyCode="3"
android:contentDescription="@string/accessibility_home"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:contentDescription="@string/accessibility_recent"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/sub"
android:background="@drawable/sub_normal"
android:layout_width="70dip"
android:layout_height="match_parent"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
systemui:keyCode="25"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/add"
android:background="@drawable/add_normal"
android:layout_width="70dip"
android:layout_height="match_parent"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
systemui:keyCode="24"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/screenshot"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_screenshot"
android:contentDescription="@string/accessibility_screenshot"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/menu"
android:layout_width="@dimen/navigation_menu_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_menu"
systemui:keyCode="82"
android:visibility="invisible"
android:contentDescription="@string/accessibility_menu"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
</LinearLayout>
<!-- fake space bar zone -->
<com.android.systemui.statusbar.policy.EventHole android:id="@+id/fake_space_bar"
android:layout_height="match_parent"
android:layout_width="0dp"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:layout_toRightOf="@+id/navigationArea"
android:layout_toLeftOf="@+id/notificationArea"
android:visibility="gone"
/>
</RelativeLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/bar_shadow_holder"
android:layout_width="match_parent"
android:layout_height="@*android:dimen/system_bar_height"
android:layout_gravity="bottom"
>
<!-- lights out shade -->
<RelativeLayout
android:id="@+id/bar_shadow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000"
android:visibility="gone"
>
<ImageView
android:id="@+id/dot0"
android:layout_width="80dip"
android:layout_height="48dip"
android:src="@drawable/ic_sysbar_lights_out_dot_small"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<ImageView
android:id="@+id/dot1"
android:layout_width="80dip"
android:layout_height="48dip"
android:src="@drawable/ic_sysbar_lights_out_dot_large"
android:layout_toRightOf="@+id/dot0"
android:layout_alignParentBottom="true"
/>
<ImageView
android:id="@+id/dot2"
android:layout_width="80dip"
android:layout_height="48dip"
android:src="@drawable/ic_sysbar_lights_out_dot_small"
android:layout_toRightOf="@+id/dot1"
android:layout_alignParentBottom="true"
/>
<ImageView
android:id="@+id/dot3"
android:layout_width="80dip"
android:layout_height="48dip"
android:src="@drawable/ic_sysbar_lights_out_dot_small"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</FrameLayout>
</com.android.systemui.statusbar.tablet.TabletStatusBarView>
在该文件中设置了add按钮(即音量加按钮)和sub按钮(即音量减按钮)的属性,android:visibility="invisible"设置为不可见
但是这样不能达到切换横竖屏的时候的消失和显示的效果。
然后我查看了mx0831-0525\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tablet\TabletStatusBar.java文件
然后修改了该文件的onConfigurationChanged(Configuration newConfig)方法,修改如下
@Override
protected void onConfigurationChanged(Configuration newConfig) {
loadDimens();
//edited by ouyangpeng start
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
mVolumeUpButton.setVisibility(View.VISIBLE);
mVolumeDownButton.setVisibility(View.VISIBLE);
}else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
mVolumeUpButton.setVisibility(View.GONE);
mVolumeDownButton.setVisibility(View.GONE);
}
//edited by ouyangpeng end
mNotificationPanelParams.height = getNotificationPanelHeight();
WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel,
mNotificationPanelParams);
mRecentsPanel.updateValuesFromResources();
mShowSearchHoldoff = mContext.getResources().getInteger(
R.integer.config_show_search_delay);
updateSearchPanel();
}
这样就可以根据android横竖屏来动态设置音量键的消失和显示了。
==================================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
==================================================================================================
分享到:
相关推荐
Android系统移植(一)-让android系统在目标平台上运行起来 18 Android系统移植(二)-按键移植 20 Android系统移植(三)-按键字符表 25 android启动过程配置文件的解析与语法 28 android系统开发(四)-触摸屏tslib移植...
介绍怎样移植android系统到不同嵌入式平台,以android模拟器内核goldfish,高通MSM平台,德州仪器OMAP平台来例子介绍如何移植android系统。
《Android系统级深入开发:移植与调试》是一本全面介绍Android系统级开发的作品,全书以移植和调试为重点。Android具有一个庞大的软件系统,任何开发者都难以掌握系统的每一个细节。因此,如何高效地理解和开发系统,...
android-移植调试-用户输入系统android-移植调试-用户输入系统
[14本经典Android开发教程]-11-Android系统移植技术详解 -------------------------------------------------- (1)安装如下软件包 sudo apt-get install git-core sudo apt-get install gnupg sudo apt-get install...
《Android系统级深入开发——移植与调试》是一本全面介绍Android系统级开发的作品,全书以移植和调试为重点。Android具有一个庞大的软件系统,任何开发者都难以掌握系统的每一个细节。因此,如何高效地理解和开发...
android-移植调试-openMax多媒体引擎android-移植调试-openMax多媒体引擎
Android系统移植与平台开发,将网络上面零散的连载文章整理合并成一个完整的文档,供Android系统开发人员学习与参考。
Android系统级深入开发——移植与调试
Android系统级深入开发——移植与调试 pdf
android系统级深入开发
Android系统级深入开发——移植与调试.pdf 高清完整版下载
Android系统级深入开发——移植与调试02
深入浅出-Android系统移植与平台开发(2)_准备Android开发环境[收集].pdf
可以移植到android平台实现NTFS文件系统挂载读写
介绍怎样移植android系统到不同嵌入式平台,以android模拟器内核goldfish,高通MSM平台,德州仪器OMAP平台来例子介绍如何移植android系统。
《Android系统级深入开发:移植与调试》是一本全面介绍Android系统级开发的作品,全书以移植和调试为重点。Android具有一个庞大的软件系统,任何开发者都难以掌握系统的每一个细节。因此,如何高效地理解和开发系统...
书名:《Android底层开发技术实战详解——内核、移植和驱动》(电子工业出版社.王振丽)。本书从底层原理开始讲起,结合真实的案例向读者详细介绍了android内核、移植和驱动开发的整个流程。全书分为19章,依次讲解...