android沉浸式状态栏与text文字设置多种颜色

沉浸式状态栏


只支持4.4以上版本,4.4效果为渐变透明色,5.0支持全透明状态栏

1.首先配置沉浸式(透明状态栏)样式主题
values-v19
styles.xml

    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

values-v21
styles.xml

    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus">false</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

2.清单文件对应的activity引用刚才创建的主题

        <activity
            android:name=".module.login.LoginActivity"
            android:theme="@style/TranslucentTheme" />
        <activity

3.对应activity布局文件的根布局中加入android:fitsSystemWindows=”true”
或代码实现

        ViewGroup contentFrameLayout = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT);
        View parentView = contentFrameLayout.getChildAt(0);
        parentView.setFitsSystemWindows(true);

text文字设置多种颜色

1.添加字符串配置
values
strings.xml

<string name="register_read_service"><Data><![CDATA[我已仔细阅读并同意《<font color="#52affc">服务协议</font>》]]></Data></string>

2.代码初始化值的时候使用html工具格式化成对应的html效果

mRegisterRead.setText(Html.fromHtml(getResources().getString(R.string.register_read_service)));

猜你喜欢

转载自blog.csdn.net/opopopwqwqwq/article/details/80278959