当前位置: 首页 > news >正文

php网站出现乱码app推广拉新一手渠道

php网站出现乱码,app推广拉新一手渠道,归客手游代理平台,如何做好企业推广支持&#xff1a;XML 与代码动态设置电量&#xff08;0–100&#xff09;充电 charging 与快充 fastCharging 区分&#xff08;闪电样式 动画&#xff09;电量阈值自动配色&#xff1a;<20% 红、<50% 橙、≥50% 绿可配置边框/轨道/电量/闪电颜色&#xff1b;可显示百分比…

支持:

  • XML 与代码动态设置电量(0–100)

  • 充电 charging 与快充 fastCharging 区分(闪电样式 + 动画)

  • 电量阈值自动配色:<20% 红、<50% 橙、≥50% 绿

  • 可配置边框/轨道/电量/闪电颜色;可显示百分比文本

  • 支持无障碍(contentDescription、AccessibilityLiveRegion)

  • 支持状态保存(旋转/进程重建)

  • 平滑动画过渡(setLevelAnimated)

1、自定义属性 res/values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="BatteryView">
<attr name="bv_level" format="integer"/>
<attr name="bv_showPercentage" format="boolean"/>
<attr name="bv_charging" format="boolean"/>
<attr name="bv_fastCharging" format="boolean"/><attr name="bv_borderColor" format="color"/>
<attr name="bv_trackColor" format="color"/>
<attr name="bv_fillColor" format="color"/>
<attr name="bv_lowColor" format="color"/>
<attr name="bv_mediumColor" format="color"/>
<attr name="bv_highColor" format="color"/>
<attr name="bv_boltColor" format="color"/><attr name="bv_borderWidth" format="dimension"/>
<attr name="bv_cornerRadius" format="dimension"/>
<attr name="bv_capWidth" format="dimension"/>
<attr name="bv_capGap" format="dimension"/>
<attr name="bv_textSize" format="dimension"/>
</declare-styleable>
</resources>

术语说明:

  • borderColor:电池外框线条颜色。

  • trackColor:电池内部“轨道/背景”颜色(未被电量填充区域)。

  • fillColor:电量填充的基础颜色(当未启用分段阈值或外部强制指定时)。

2、 组件代码 BatteryView.kt

package com.yourpkg.widget
val y6 = t + h * 0.35fboltPath.reset()
boltPath.moveTo(x1, y1)
boltPath.lineTo(x2, y2)
boltPath.lineTo(x3, y3)
boltPath.lineTo(x4, y4)
boltPath.lineTo(x5, y5)
boltPath.lineTo(x6, y6)
boltPath.close()
}
// endregion// region — Accessibility
private fun updateContentDesc() {
val charge = when {
fastCharging -> "(快充中)"
charging -> "(充电中)"
else -> ""
}
contentDescription = "电量 $level%$charge"
}
// endregion// region — State
override fun onSaveInstanceState(): Parcelable? {
val superState = super.onSaveInstanceState()
return SavedState(superState).also {
it.level = level
it.charging = charging
it.fastCharging = fastCharging
it.showPercentage = showPercentage
it.chargePulse = chargePulse
}
}override fun onRestoreInstanceState(state: Parcelable?) {
val ss = state as? SavedState
super.onRestoreInstanceState(ss?.superState ?: state)
ss?.let {
level = it.level
charging = it.charging
fastCharging = it.fastCharging
showPercentage = it.showPercentage
chargePulse = it.chargePulse
toggleChargeAnim(charging)
}
}private class SavedState : BaseSavedState {
var level: Int = 0
var charging: Boolean = false
var fastCharging: Boolean = false
var showPercentage: Boolean = false
var chargePulse: Float = 0fconstructor(superState: Parcelable?) : super(superState)
private constructor(inParcel: Parcel) : super(inParcel) {
level = inParcel.readInt()
charging = inParcel.readInt() == 1
fastCharging = inParcel.readInt() == 1
showPercentage = inParcel.readInt() == 1
chargePulse = inParcel.readFloat()
}
override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)
out.writeInt(level)
out.writeInt(if (charging) 1 else 0)
out.writeInt(if (fastCharging) 1 else 0)
out.writeInt(if (showPercentage) 1 else 0)
out.writeFloat(chargePulse)
}
companion object {
@JvmField val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
override fun createFromParcel(source: Parcel): SavedState = SavedState(source)
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
}
}
}
// endregion// region — Utils
private fun dp(v: Float) = v * resources.displayMetrics.density
private fun sp(v: Float) = v * resources.displayMetrics.scaledDensity
// endregion
}

3、XML 用法示例

<com.yourpkg.widget.BatteryView
android:id="@+id/battery"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_margin="16dp"
app:bv_level="45"
app:bv_showPercentage="true"
app:bv_charging="true"
app:bv_fastCharging="false"app:bv_borderColor="#222222"
app:bv_trackColor="#F2F2F2"
app:bv_lowColor="#E53935"
app:bv_mediumColor="#FB8C00"
app:bv_highColor="#43A047"
app:bv_boltColor="#FFFFFF"app:bv_borderWidth="2dp"
app:bv_cornerRadius="8dp"
app:bv_capWidth="7dp"
app:bv_capGap="2dp"
app:bv_textSize="12sp"/>

4、代码控制示例

val bv = findViewById<BatteryView>(R.id.battery)// 动态设置电量
bv.level = 18 // 立即刷新
bv.setLevelAnimated(76) // 平滑动画到 76%// 充电状态
bv.charging = true // 显示闪电 + 呼吸动画
bv.fastCharging = true // 闪电更大、视觉更强// 开关百分比
bv.showPercentage = false// 结合业务:阈值配色自动处理(<20 红、<50 橙、≥50 绿),无需额外代码

5、常见问题(结合你之前的疑问)

  • Q: borderColor 和 trackColor 是什么?
    A: borderColor 是外框线条;trackColor 是内部未充满的背景。

  • Q: 无障碍报错 isImportantForAccessibility
    A: 组件内已设置:

    importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES

    accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE

    同时动态更新 contentDescription,读屏会播报“电量 76%,快充中”。

  • Q: 如何自定义颜色?
    在 XML 传入 bv_lowColor/bv_mediumColor/bv_highColor,或在代码里直接修改。

  • Q: 性能如何?
    组件绘制简单,动画为轻量级呼吸,postOnAnimation 驱动,开销极低。

6、小扩展(可选)

  • 电量渐变色:将 fillPaint 设置为 LinearGradient,根据 level 动态改变 endX。

  • 低电量闪烁:level<10 且非充电时,使用 alpha 在 120–255 之间脉动。

  • RTL 适配:当 layoutDirection == LAYOUT_DIRECTION_RTL 时从右向左填充(可根据需要调整 fillRect 计算)。

http://www.dtcms.com/a/599220.html

相关文章:

  • 电气工程师求职问答-中级篇
  • 个人博客网站备案吗最简单的网站怎么做
  • 织梦更新网站地图画网站 模板
  • 个人网站 做外贸wordpress安卓显示
  • 峰值保持电路与峰值提取算法实现放射性核脉冲信号峰值提取
  • 内网网站搭建设推销什么企业做网站和app
  • 开源展示型网站莱芜百度贴吧
  • 做网站要注意的wordpress找回密碼
  • 东莞网站建设 光龙做网站备案哪些条件
  • 维护网站建设空间出租怎么生成链接
  • 搜狗推广做网站要钱吗手机网站怎么搜索引擎
  • 第5天python内容
  • 网站建设进展报告做excel的网站
  • 怎样做付费下载的网站wordpress 引用 插件
  • 连云港市建设银行网站wordpress排除首页显示
  • 内江市规划建设教育培训中心网站wordpress 微信公众
  • 国外的贸易网站智能营销系统
  • android 线程loop
  • 自己的网站如何给别人做有偿广告网站开发的目的意义
  • 代码随想录 134.加油站
  • 专门做水产海鲜的网站吗网站添加视频
  • 电子电气架构 --- 整车EEA简述
  • 双辽建设局网站手工制作房子
  • 网站服务器慢福田在线官网
  • 54.渗透-Yakit-基础模块应用(子域名收集)
  • 化妆品网站程序熟悉网站空间 域名等相关知识
  • Carla仿真多跳转发功能开发
  • 变量捕获相关内容
  • 【ZeroRange WebRTC】NAT 与防火墙在 WebRTC 中的影响
  • 交互设计作品集网站wordpress 增加其它语言