Android实现切换主题颜色

最近看到网易云的换肤不错,就想自己来实现一下

  • 效果图
  • 使用到的相关小技术

效果图

切换主题颜色

使用到的相关小技术

1、PopWindow
2、RecyclerView
3、沉浸式状态栏
大概就这三个吧

首先说一下首页布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF9F38"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.bxy.themecolordemo.MainActivity">

    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:background="#FF9F38"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="主 题 换 肤"
            android:textColor="@android:color/white"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/white"
        android:layout_weight="1">

        <Button
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_margin="15dp"
            android:background="#FF9F38"
            android:text="选择颜色"
            android:textColor="@android:color/white" />
    </LinearLayout>
</LinearLayout>

默认的界面效果就是这样的:

这里写图片描述

在Java代码里分别获取到控件

btn=(Button)findViewById(R.id.btn);
ll=(LinearLayout)findViewById(R.id.ll);
title=(LinearLayout)findViewById(R.id.activity_main);

接下来是自定义的popwindow:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pop_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width
  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值