Android13:SystemUI 之DIY锁屏界面

此文适用于Android13:

在bom开发中,可能会遇到需要修改任何systemUI的地方,因此为了减少寻找文件的时间,和挨个试错的次数,这里讲提供较常用的布局修改,针对于锁屏界面的。

一、首先在锁屏界面,有通知和无通知是两种形式,如果有通知则是:

<!-- 这个是有通知情况下的时间界面--
对应文件路径为:system/vendor/mediatek/proprietary/packages/apps/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml
-->
<FrameLayout
        android:id="@+id/lockscreen_clock_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        >
        <com.android.keyguard.AnimatableClockView
            android:id="@+id/animatable_clock_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center_horizontal"
            android:textSize="@dimen/clock_text_size"
            android:fontFamily="@font/clock"
            android:elegantTextHeight="false"
            android:singleLine="true"
            android:fontFeatureSettings="pnum"
            chargeAnimationDelay="350"
            dozeWeight="200"
            lockScreenWeight="400"
        />
</FrameLayout>

二、如果没有通知

<!--如下是没有通知的情况下的时间界面
对应文件路径为:system/vendor/mediatek/proprietary/packages/apps/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml
 -->   
<LinearLayout
        android:id="@+id/keyguard_status_area"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:paddingTop="20dp"
        android:layout_below="@id/lockscreen_clock_view">
 
      <include layout="@layout/keyguard_slice_view"
               android:id="@+id/keyguard_slice_view"
               android:layout_width="match_parent"
               android:layout_height="wrap_content" />
 
      <com.android.systemui.statusbar.phone.NotificationIconContainer
          android:id="@+id/left_aligned_notification_icon_container"
          android:layout_width="match_parent"
          android:layout_height="@dimen/notification_shelf_height"
          android:paddingStart="@dimen/below_clock_padding_start_icons"
          android:visibility="invisible"
          />
    </LinearLayout>
 
<!--如下是具体时间界面的实现,
对应文件路径为:system/vendor/mediatek/proprietary/packages/apps/SystemUI/res-keyguard/layout/keyguard_slice_view.xml
 -->   
 
<com.android.keyguard.KeyguardSliceView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:clipToPadding="false"
    android:orientation="vertical"
    android:layout_marginBottom="30dp">
    <TextView
              android:id="@+id/title"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:visibility="gone"
              android:textColor="?attr/wallpaperTextColor"
              android:theme="@style/TextAppearance.Keyguard"
    />
    <view class="com.android.keyguard.KeyguardSliceView$Row"
              android:id="@+id/row"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:gravity="center"
    />
</com.android.keyguard.KeyguardSliceView>

三、锁定图标通过java文件进行位置控制

//如下文件是锁屏图标所在的布局的自定义布局,当前文件为:system/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/keyguard/LockIconView.java
public void setCenterLocation(@NonNull PointF center, float radius, int drawablePadding) {
        mLockIconCenter = center;
        mRadius = radius;
        mLockIconPadding = drawablePadding;
 
        mLockIcon.setPadding(mLockIconPadding, mLockIconPadding, mLockIconPadding,
                mLockIconPadding);
 
        // mSensorProps coordinates assume portrait mode which is OK b/c the keyguard is always in
        // portrait.
        mSensorRect.set(mLockIconCenter.x - mRadius,
                mLockIconCenter.y - mRadius,
                mLockIconCenter.x + mRadius,
                mLockIconCenter.y + mRadius);
 
        final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
        lp.width = (int) (mSensorRect.right - mSensorRect.left);
        lp.height = (int) (mSensorRect.bottom - mSensorRect.top);
        //例如这里的需求是锁屏界面的锁定图标需要在顶部,因此把之前的改为70,定位就上去了
        // lp.topMargin = (int) mSensorRect.top;
        lp.topMargin = 70;
        lp.setMarginStart((int) mSensorRect.left);
        setLayoutParams(lp);
    }

四、类似其他相关修改可以针对其相关的布局,例如调整图标大小

<!-- 此处为锁屏图标的实现,比如如果需要修改锁屏图标大小也只需要调整imageView大小即可
文件所在位置为:system/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/status_bar_expanded.xml
-->
<com.android.keyguard.LockIconView
        android:id="@+id/lock_icon_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <!-- Background protection -->
        <ImageView
            android:id="@+id/lock_icon_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/fingerprint_bg"
            android:visibility="invisible"/>
 
        <ImageView
            android:id="@+id/lock_icon"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:scaleType="centerCrop"/>
 
    </com.android.keyguard.LockIconView>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值