android systemui下拉_Android系统定制之SystemUI修改:下拉通知栏尺寸【转】

最近项目需要修改下拉通知栏面板的宽度,完成后,写个Blog做个总结,也提供给需要的开发人员参考。

本文介绍了DDMS中 Dump View Hierarchy for UI Automator 工具的使用方法,通过该工具找到一些应用的布局,快速定位我们需要修改的源码位置。

1 先看下效果图

修改前,横屏状态的下拉通知栏,距离屏幕左右两边还有段距离。(模拟器中的截图,Android原生的状态)

0a3f9e126e720521210872a6c04efb62.gif

修改后,横屏状态的下拉通知栏,宽度铺满屏幕。(真实设备截图, 修改后刷机效果)

582327a1e74425295d80374933092843.gif

2 找到这部分的相关布局。

SystemUI下拉通知栏的布局为super_status_bar.xml

84c387cb77f40fc1591f85b2b420e54b.png

代码如下

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true">

android:id="@+id/backdrop"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:visibility="gone"

>

android:layout_width="match_parent"

android:scaleType="centerCrop"

android:layout_height="match_parent" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scaleType="centerCrop"

android:visibility="invisible" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:importantForAccessibility="no" />

android:layout_width="match_parent"

android:layout_height="@dimen/status_bar_height" />

android:layout_width="@dimen/notification_panel_width"

android:layout_height="wrap_content"

android:layout_gravity="@integer/notification_panel_layout_gravity"

android:paddingLeft="@dimen/notification_side_padding"

android:paddingRight="@dimen/notification_side_padding"

android:visibility="gone">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:elevation="2dp"

android:background="@drawable/brightness_mirror_background">

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@+id/panel_holder"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/transparent" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:visibility="gone" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:importantForAccessibility="no" />

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

几个关键的字眼:

| “@layout/status_bar” ————–> 状态栏

| “@+id/brightness_mirror” ——–> 下拉通知栏中调节亮度时,只剩下亮度调节弹出框,位置与下拉通知栏亮度调节位置一样的。

| “@+id/panel_holder”—————>下拉通知栏载体

| “@layout/status_bar_expanded”->下拉通知栏布局

super_status_bar.xml包含了状态栏,下拉通知栏等布局

3 找到下拉通知栏相关布局

通过 DDMS 的 Dump View Hierarchy for UI Automator 工具,我们可以抓取一些布局的ID。

57952b4dab0dfd32c208f81adf74367b.png

-3.1 header

通知栏上半部分是 com.android.systemui:id/header,那我们在SystemUI的res中,搜索这个“header” 。

91a474124ce59192025f61cbd956c838.png

搜索到layout中带有header的,有status_bar_expanded_header.xml,只有这个布局有这个ID

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:systemui="http://schemas.android.com/apk/res-auto"

android:id="@+id/header"

android:layout_width="@dimen/notification_panel_width"

android:layout_height="@dimen/status_bar_header_height"

android:layout_gravity="@integer/notification_panel_layout_gravity"

android:paddingStart="@dimen/notification_side_padding"

android:paddingEnd="@dimen/notification_side_padding"

android:baselineAligned="false"

android:elevation="4dp"

android:background="@drawable/notification_header_bg"

android:clickable="true"

android:focusable="true"

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

如果需要修改header的尺寸,可将

android:layout_width="@dimen/notification_panel_width"

1

修改为

android:layout_width="match_parent"

1

重新编译,这个header的宽度就和屏幕一样了。

-3.2 scroll_view

可上下滑动的快捷开关布局。

2983bd362d68a2b64a5aeb09b3d85c55.png

上图所示的布局代码如下

android:id="@+id/scroll_view"

android:layout_width="@dimen/notification_panel_width"

android:layout_height="match_parent"

android:layout_gravity="@integer/notification_panel_layout_gravity"

android:scrollbars="none"

android:overScrollMode="never"

android:fillViewport="true">

1

2

3

4

5

6

7

8

将宽度属性改成:

android:layout_width="match_parent"

1

-3.3 notification_stack_scroller

通知列表布局

33e9100d42a263aa41a2752a166e2ca9.png

上图所示的布局代码如下

android:id="@+id/notification_stack_scroller"

android:layout_width="@dimen/notification_panel_width"

android:layout_height="match_parent"

android:layout_gravity="@integer/notification_panel_layout_gravity"

android:layout_marginBottom="@dimen/close_handle_underlap"

android:importantForAccessibility="no" />

1

2

3

4

5

6

7

宽度属性改成:

android:layout_width="match_parent"

1

4 重新编译,打包ROM

make源码,重新刷机查看效果,可以看到文章开头的gif图所示的效果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android中,如果想要自定义下通知的颜色,可以通过修改SystemUI的相关设置来实现。 首先,为了修改SystemUI的颜色,需要获取相应的权限。我们可以在AndroidManifest.xml文件中添加如下代码: ```xml <uses-permission android:name="android.permission.STATUS_BAR"/> ``` 接下来,在我们的项目中创建一个名为values的文件夹,并在其中创建一个名为colors.xml的文件。在这个文件中,我们可以定义我们想要使用的颜色。例如,我们可以定义一个名为notification_background的颜色,用于设置下通知的背景颜色。代码如下: ```xml <resources> <color name="notification_background">#FF0000</color> </resources> ``` 然后,我们需要修改SystemUI的源代码,以更新背景颜色。具体来说,我们需要找到StatusBar类中的updateResources方法,并在该方法中添加以下代码: ```java Context context = mContext.createPackageContext("com.example.notificationtest", Context.CONTEXT_IGNORE_SECURITY); // 替换为自己的包名 int color = context.getResources().getColor(R.color.notification_background); mBackgroundView.setBackgroundColor(color); ``` 最后,我们需要重新编译并安装我们的应用程序。一旦安装完成,我们就可以看到下通知的背景颜色已经根据我们在colors.xml中定义的颜色进行了自定义。 以上是通过修改SystemUI的方式来自定义下通知的颜色。请注意,这种方式需要具备系统级权限,因此只适用于特定的Android设备。在实际开发中,请确保在使用这种方式之前了解并遵守相关的法规和政策,以避免违规行为。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值