Android系统移植与调试之------->如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏

时间:2022-09-18 21:34:40

这两天由于一个客户的要求,将MID竖屏时候的状态条上的音量键去掉。所以尝试修改了一下,成功了,分享一下经验。

先看一下修改后的效果图,如下所示 。

横屏的时候:有音量加减键Android系统移植与调试之------->如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏

竖屏的时候:音量加减键被去掉了

Android系统移植与调试之------->如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏

然后来说一说我的解决思路。

首先我查看了\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)方法,修改如下

Android系统移植与调试之------->如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏

 @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设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏的更多相关文章

  1. &lbrack;置顶&rsqb; Android系统移植与调试之-------&gt&semi;如何修改Android设备状态条上音量加减键在横竖屏的时候的切换与显示

    这两天由于一个客户的要求,将MID竖屏时候的状态条上的音量键去掉.所以尝试修改了一下,成功了,分享一下经验. 先看一下修改后的效果图,如下所示 . 横屏的时候:有音量加减键 竖屏的时候:音量加减键被去 ...

  2. Android系统移植与调试之------->如何修改Android系统默认显示【开发者选项】并默认打开【USB调试】和【未知来源】开关

    今天有个用户对[设置]有个特殊的要求,即: 1.开机的时候默认显示[开发者选项]并打开[USB调试]开关    ([Developer options]-->[USB debugging]) 2 ...

  3. Android系统移植与调试之------->如何修改Android手机显示的4G信号强度的格子数

    在修改显示的信号强度之前,先了解一下什么是dB,什么是dBm? 1.dB dB是一个表征相对值的值,纯粹的比值,只表示两个量的相对大小关系,没有单位,当考虑甲的功率相比于乙功率大或小多少个dB时, 按 ...

  4. Android系统移植与调试之------->如何修改Android设备添加重启、飞行模式、静音模式等功能(二)

    今天要说的是为Android设备添加重启.飞行模式.静音模式按钮,客户需求中需要添加这项功能,在长按电源键弹出的菜单中没有这些选项,谨以此文记录自己添加这个功能的过程. 首先找到长按电源键弹出的对话框 ...

  5. Android系统移植与调试之------->如何修改Android手机NFC模块,使黑屏时候能够使用NFC

    我们都知道在不修改源代码的情况下,只能是解锁之后才能使用NFC功能.而在锁屏和黑屏2个状态下是没办法用NFC的,但是最近有个客户要求手机在黑屏状态下能够使用NFC,因此我们需要去修改Android源代 ...

  6. Android系统移植与调试之------->如何修改Android设备存储盘符名称与Android设备的型号

    一.修改Android设备存储盘符名称 (注:TBDG1073为我的项目名称) 1.修改device/other/TBDG1073/system.prop 文件 2.修改ro.media.patiti ...

  7. Android系统移植与调试之------->如何修改Android自带的apk出现一圈圈类似鸡蛋的花纹

    最近被一个问题烦恼到了,就是android4.1系统自带的Email.文件管理器.信息等apk都出现同一个问题,就是现实在平板上的时候会出现一圈圈类似鸡蛋的花纹. 我想了两种方法来解决,第一种方法没有 ...

  8. Android系统移植与调试之------->如何修改Android默认字体大小和设置里面字体大小比例

    因为我修改 ro.sf.lcd_density的值,将它从160修改 为120,所以导致整个系统的字体都变得很小.因此需要将整个字体变大,并且在设置-->显示-->字体大小的4个选项的值都 ...

  9. &lbrack;置顶&rsqb; Android系统移植与调试之-------&gt&semi;如何修改Android设备添加3G上网功能

    1.首先先来看一下修改前后的效果对比图 step1.插上3G设备前 step2.插上3G设备后,获取信号中.... step3.插上3G设备后,获取到信号 step4.使用3G信号浏览网页 2.下面讲 ...

随机推荐

  1. linux下编译安装vim7&period;4并安装clang&lowbar;complete插件

    linux下编译安装vim7.4并安装clang_complete插件 因为debian里软件仓库中下载安装的vim是不支持python写的插件的(可以打开vim,在命令模式先输入:py测试一下),导 ...

  2. PHPExcel导出功能

    对于第一次弄这个导出,总结下思路: 1.下载在http://phpexcel.codeplex.com/下载最新PHPExcel放到Vendor下,注意位置:ThinkPHP\Extend\Vendo ...

  3. leetcde37&period; Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  4. 《30天自制操作系统》09&lowbar;day&lowbar;学习笔记

    harib06a: 在昨天的最后一部分,我们已经变成了32位的模式,目的就是希望能够使用电脑的全部内存. 虽然鼠标的显示处理有一些叠加问题,不过笔者为了不让我们感到腻烦,先带我们折腾一下内存 这里笔者 ...

  5. NET基础课--泛型&lpar;NET之美&rpar;

    1.泛型,类型或方法的一种抽象概括. 2.泛型类:在类型名后面加一个<>,其中传递占位符,也就是类型参数.where是类型约束 可以再查资料 public class SortHelper ...

  6. Hdu 1698&lpar;线段树 区间修改 区间查询&rpar;

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  7. ResultSet的getInt&lpar;&rpar;和getString&lpar;&rpar;方法详解

     数据库tt的examstudent数据表如下:   在MySQL中执行查询语句如下: ResultSet rs = null; String sql="SELECT flow_id,Typ ...

  8. C&lowbar;使用clock()函数获取程序执行时间

    clock():捕捉从程序开始运行到clock()被调用时所耗费的时间.这个时间单位是clock tick ,即“时钟打点”. 常数CLK_TCK:机器时钟每秒所走的时钟打点数. #include & ...

  9. 新工具DPR的一些想法

    可行性分析 假设: 连续性 - 与clustering的假设正好相反 分支事件 特征的选择:距离的度量: 限定KNN的必要性: MST构建: 主支的构建和简化:省略中间点:最短路径: 迭代处理所有分支 ...

  10. 【BZOJ4946】&lbrack;NOI2017&rsqb;蔬菜(贪心)

    [BZOJ4946][NOI2017]蔬菜(贪心) 题面 BZOJ 洛谷 UOJ 题解 忽然发现今年\(NOI\)之前的时候切往年\(NOI\)的题目,就\(2017\)年的根本不知道怎么下手(一定是 ...