安卓实现仿系统设置界面

前言

这几天在做项目的空闲时间突然对界面产生了及其浓厚的兴趣,也许是从进公司以来都是我一人来进行安卓开发,所以界面也是只能我一个人来搞,所以闲暇时间还要研究研究一下界面的,这不,昨天闲来无事翻手机,突然进入到了系统的设置界面,然后突然觉得还挺美观的,然后就仿了一个差不多的界面。这里做一个记录,以便往后翻看,其次,如果能够帮助到一些需要帮助的同行,那真是再好不过了。

先上效果图

通过上面的效果图显示,其中有几个点是我们需要注意的。

  1. 显示在全屏的背景图。(适配于所有手机)
  2. ActionBar( 顶部导航栏 )同状态栏合为一体。
  3. 图标的ImageView的背景透明。
上面所列出的注意事项即是我们要突破的技术难题,当然在大牛的眼中根本不是什么技术难题,这里只是对像我这种的安卓小白来说的。好了,废话不多说,接下来就是实现步骤。
1. 第一个问题是如何将一张背景图适配于所有的手机屏幕?

① 其实官方文档给出的解决办法是为不同屏幕大小的手机准备该背景图的不同分辨率图片。然后再创建drawable-hdpi、drawable-mdpi、drawable-xhdpi等一系列文件夹,然后把相应分辨率的图片放入其中,这样程序在运行的时候会根据手机屏幕的大小自动选取最佳的图片进行显示。
② 可是作为一名后端的安卓小白,又不精通设计以及使用ps画出精美的符合规格的图片,然后通过原型图改成规格不同的图片。那么我们该如何去获取一张比较美观的背景图呢,这里我的解决方案呢,是在Pexels上去找,这里有很多精美的图片,都是可以免费商用的。我觉得上面的图片基本上能够满足一般的开发需求。
③ 背景图片已经解决了,那么还有个适配问题又该如何解决呢,因为我们在Pexels上获取到的图片一般都是不规则的,但是分辨率还是比较高的。虽然我们不能对图片进行修改,制作适用于所有手机屏幕的图片集。可是我们可以利用分辨率极高的特点来做些事情,我们知道如果图片的分辨率大于手机的分辨率的话,那么图片在手机屏幕上呈现的效果将是图片的分辨率是手机屏幕分辨率上限的效果。而我看了一下背景图片,发现该图片的分辨率及其的高,反正是高于普遍的手机分辨率的。然后再在软件开启时不让它自动调整图片的分辨率即可,而项目的drawable-nodpi文件夹的作用即是让程序在使用里面的图片时不自动调整大小。因为是安卓小白,不知道该方法理论到底对不对,如果不对,欢迎留言指出。

④ 最后总结出来,我们真正要做的就是在Pexels上找一张比较美观的背景图,然后在项目的res文件夹下创建drawable-nodpi文件夹,然后再把下载下来的背景图放入该文件夹即可。

2. 第二个问题是如何将ActionBar同状态栏合为一体?

① 这个问题在我的上篇博文安卓利用ToolBar实现控件实现仿QQ顶部渐变色效果中做了一些讲解,不懂的可以先去看看那篇博文。

② 这里呢同上篇博文用到的库是同一个库,只是要用到的方法不同了。用的如下方法:
 //将toolbar同状态栏合为一体StatusBarUtil.setTransparentForWindow(this);//这里要根据背景图的整体色调是亮色还是暗色来进行选择状态栏字体的色调//设置状态栏的字体颜色为亮色StatusBarUtil.setLightMode(this);//设置状态栏的字体颜色为暗色//StatusBarUtil.setDarkMode(this);
3. 第三个问题是如何将显示图标的ImageView的背景设置为透明的呢?

① 经常使用ImageView的朋友会发现,当要放入的图片不是方方正正时,ImageView控件中没有填满的部分将会是灰白色的。那么如何来解决这个问题呢,其实很简单。

② 我们只需要将ImageView的背景色改成透明的即可,这样我们图片没有占满的地方将不再会是灰白色的了。

android:background="#00000000"

其中“#00000000”最前面的两个0是指的透明度,00即是代表全透明,e0即是代表半透明。后面的六位0即是代表颜色。
4.好了,所有问题我们都已解决,现在来进行实现,贴出所有代码,代码里有注释,就不再另做说明。

① 界面代码activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/starsky"tools:context=".MainActivity"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:minHeight="?attr/actionBarSize"><TextViewandroid:id="@+id/tv_toolbar_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="50dp"android:singleLine="true"android:textStyle="bold"android:textColor="#ffffff"android:textSize="20sp"/></androidx.appcompat.widget.Toolbar><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_mydevice"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="我的设备"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_sim"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="双卡与移动网络"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_wifi"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="WLAN"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_bluetooth"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="蓝牙"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_vpn"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="VPN"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_moreconnecttype"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="更多连接方式"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="30dp"android:layout_marginRight="30dp"android:background="#8a8a8a"></View><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_lock"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="锁屏"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_light1"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="显示"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_voice"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:textSize="16sp"android:textStyle="bold"android:textColor="#ffffff"android:layout_gravity="center"android:text="声音与振动"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="#00000000"android:src="@drawable/ic_skip"/></LinearLayout></LinearLayout></LinearLayout>
</LinearLayout>
注意:这里所有的图标可以看的以前的博文进行获取添加。传送门Android开发图标适配手机方案

② 后台代码MainActivity.class:

package com.example.backgroundtestdemo01;import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;import android.os.Bundle;
import android.widget.TextView;import com.leaf.library.StatusBarUtil;public class MainActivity extends AppCompatActivity {private static final String TAG = "MainActivity";private Toolbar toolbar;//ToolBar的居中标题栏private TextView tv_toolbar_title;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//获取到toolbar的控件实例toolbar = (Toolbar) findViewById(R.id.toolbar);//设置系统的Actionbar为toolbarsetSupportActionBar(toolbar);tv_toolbar_title = (TextView) findViewById(R.id.tv_toolbar_title);//设置toolbar的居中标题栏文本tv_toolbar_title.setText("设置");//将toolbar同状态栏合为一体StatusBarUtil.setTransparentForWindow(this);//这里要根据背景图的整体色调是亮色还是暗色来进行选择状态栏字体的色调//设置状态栏的字体颜色为亮色StatusBarUtil.setLightMode(this);//设置状态栏的字体颜色为暗色//StatusBarUtil.setDarkMode(this);//获取到toolbarActionBar actionBar = getSupportActionBar();if(actionBar != null){//取消到toolbar原本不能居中的标题栏actionBar.setDisplayShowTitleEnabled(false);}}
}
注意:
① 要将软件的风格改为NoActionbar的风格。如何更改在安卓利用ToolBar实现控件实现仿QQ顶部渐变色效果可以找到。
② 要使用StatusBarUtil.setTransparentForWindow(this);方法前要先导入一个包,导入方法在安卓利用ToolBar实现控件实现仿QQ顶部渐变色效果可以找到。
//所要导入的包implementation 'com.github.Ye-Miao:StatusBarUtil:1.7.5'

好啦,做完这些我们就可以看到一个比较精美的设置界面了,不再会像以前那像有点拿不出手了。如果你看到了这,那么恭喜你,你的经验又增长了一丢丢,离升级又近了一步。这里希望正在努力奋斗的同伴可以一直勇往无前,最终到达自己成功的彼岸!加油!

安卓实现仿系统设置界面相关推荐

  1. 安卓开发— —仿微信界面(一)

    目录 一.项目内容 二.代码实现 1.项目结构 2.头部代码 3.底部代码 4.四个内容界面 5.窗体总布局 6.MainActivity实现点击图标与页面的互动 三.运行效果 四.总结 一.项目内容 ...

  2. 安卓开发— —仿微信界面(二)

    一.项目内容 对聊天主界面weixinFragment进行完善,使用recyclerView实现滚动列表,并实现点击联系人展开显示详细聊天信息. 开发环境:Android Studio.Android ...

  3. 安卓仿微信界面,导航,右上角菜单栏

    下面是安卓开发仿微信界面的代码. 分为3步,第一步是界面的编写,第二步是导航界面,第三步是右上角菜单栏. 开始第一步前先预览一下效果. 第一步,界面. 界面的思路是利用ViewPager+Fragme ...

  4. Qt之高仿QQ系统设置界面

    QQ或360安全卫士的设置界面都是非常有特点的,所有的配置项都在一个垂直的ScrollArea中,但是又能通过左侧的导航栏点击定位.这样做的好处是既方便查看指定配置项,又方便查看所有配置项. 一.效果 ...

  5. 仿qq左滑删除listview_Java基于Swing和Netty仿QQ界面聊天小项目

    点击上方 好好学java ,选择 星标 公众号 重磅资讯.干货,第一时间送达 今日推荐:硬刚一周,3W字总结,一年的经验告诉你如何准备校招! 个人原创100W+访问量博客:点击前往,查看更多 来源:b ...

  6. android仿iphonex home,安卓高仿iPhoneX桌面

    安卓高仿iPhoneX桌面是一款非常装逼的手机主题软件,这款软件可以快速的让安卓手机变成iPhoneX桌面,演变效果非常的逼真,还有超强的壁纸外表,下面西西就为大家带来安卓高仿iPhoneX桌面软件最 ...

  7. android+高仿iphone,网购iPhone7P的失败经历,原来是安卓高仿!

    原标题:网购iPhone7P的失败经历,原来是安卓高仿! 大家都有网购的经历,有时候能买到便宜的好货,有时候却差强人意!但是大多人还是幸运的,为什么呢?因为他们至少在买手机没有上过当,但是当骗子遇到小 ...

  8. 是男人就下100层【第一层】——高仿微信界面(4)

    上一篇<是男人就下100层[第一层]--高仿微信界面(3)>中我们完成了登录,这一篇看完成登录后的一个短暂加载和引导界面. 加载界面: <RelativeLayout xmlns:a ...

  9. android+qq底部界面,Android 高仿QQ 界面滑动效果

    Android高仿QQ界面滑动效果 点击或者滑动切换画面,用ViewPager实现, 首先是布局文件: android:layout_width="match_parent" an ...

  10. WPF仿微信界面发送消息简易版

    WPF仿微信界面发送消息简易版 参考别的博主的例子用WPF MVVM框架来仿了一个微信聊天界面,做了个发送消息简易功能,下面一起来看看吧! 以下为View视图布局代码,消息对话框的样式直接在这里定义了 ...

最新文章

  1. 本科发表6篇SCI论文,获多个荣誉,他刚入学就享受研究生待遇!
  2. 28. extjs中Ext.BLANK_IMAGE_URL的作用
  3. 【研发管理】中国企业 VS 世界优秀企业在产品研发上差距(下)
  4. 使用python数据分析_如何使用Python提升您的数据分析技能
  5. 两条边延长角会有什么变化_《认识角》教学设计
  6. leetcode448-Find All Numbers Disappeared in an Array
  7. 用css3做一个求婚小动画
  8. PIPI-OJ BUG log
  9. 使用sql语句查询access数据库
  10. 计算机在微表情的应用,一种有效的微表情自动识别方法
  11. Linux 进程管理
  12. Linux内核文件系统7
  13. 用JQuery实现简单计时答题游戏
  14. 【verbs】ibv_reg_mr()
  15. 网页制作:制作一个官网
  16. 注册时添加学号Idnumber
  17. python 柱状图 内部颜色_Matplotlib/seaborn柱状图使用不同的颜色分组存储箱
  18. 【c++入门(2)】贪心训练
  19. git报错 git libpng warning: iCCP以及fatal: Authentication failed for ‘https://git.weixin.qq.com‘
  20. matlab 双点光源干涉的模拟,基于MATLAB的双点光源干涉现象的模拟

热门文章

  1. kubectl 命令详解(三十三):rollout resume
  2. 转胡一虎Blog:父亲是我生命中的永恒
  3. 阿里面试题 ——输入一个字符串,输出所有的排列
  4. Java编程思想-并发(5)
  5. 【分享】VMOS Pro1.4.2最新会员版
  6. jcp jsr_“ IBM和Red Hat *不应*都保留其JCP EC席位”
  7. python画图方法_python画图的两种方法
  8. 计算机科学论文生成器,软件自动生成假论文:满篇废话
  9. 龙果支付 mysql_龙果支付系统怎么搭建与部署?
  10. python模拟预测孩子身高_这个公式可以帮你预测你家孩子身高