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

设计网站推荐提升审美百度查询最火的关键词

设计网站推荐提升审美,百度查询最火的关键词,小米开发者模式,h5页面制作软件教程最近在做一个使用接口返回的字符串:"#ff0000" 来动态设置drawable背景颜色与动态设置状态选择器selector的需求,之前写习惯了shape的xml,还是第一次写动态的,有点搞笑,搞笑的是自己没写过,不知道…

最近在做一个使用接口返回的字符串:"#ff0000" 来动态设置drawable背景颜色与动态设置状态选择器selector的需求,之前写习惯了shape的xml,还是第一次写动态的,有点搞笑,搞笑的是自己没写过,不知道会不会写。

1.很简单,直接布局代码:

<RelativeLayoutandroid:id="@+id/ll_title"android:layout_width="match_parent"android:layout_marginRight="20dp"android:layout_marginLeft="20dp"android:layout_height="50dp"app:contentInsetStart="0dp"android:background="@drawable/shape_red_bg"tools:ignore="MissingConstraints"><TextViewandroid:id="@+id/toolbar_left"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:gravity="center"android:singleLine="true"android:text="菜单"android:textColor="@color/white"android:textSize="16dp"android:visibility="visible" /><TextViewandroid:id="@+id/toolbar_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:singleLine="true"android:text="居中标题"android:layout_centerInParent="true"android:textColor="@android:color/white"android:textSize="20dp"android:visibility="visible" /><TextViewandroid:id="@+id/toolbar_right"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:layout_marginRight="10dp"android:gravity="center"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:text="秘密"android:textColor="@color/white"android:textSize="16dp"android:visibility="visible" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!--    <size android:height="417dp" android:width="834dp"/>--><gradientandroid:gradientRadius="417dp"android:startColor="@color/red"android:endColor="@color/red"android:centerX="0.5"android:centerY="1"android:type="radial" /><cornersandroid:bottomLeftRadius="0dp"android:bottomRightRadius="0dp"android:topLeftRadius="0dp"android:topRightRadius="0dp" />
</shape>

2.Activity代码如下:

//在Activity的初始化中直接复制下面代码:
RelativeLayout llTitle = findViewById(R.id.ll_title);
llTitle.setBackgroundDrawable(getStateListDrawable());llTitle.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {}});//在Activity中的方法
public static StateListDrawable getStateListDrawable() {StateListDrawable selector = new StateListDrawable();int parseColor = Color.parseColor("#FF00FF");Drawable pressDrawable = getRoundRectDrawable(20, Color.parseColor("#ff00ff"), true, 0);Drawable selectDrawable = getRoundRectDrawable(20, Color.parseColor("#00ffff"), true, 0);Drawable defaultDrawable = getRoundRectDrawable(20, Color.parseColor("#00ffff"), true, 0);selector.addState(new int[]{android.R.attr.state_pressed}, pressDrawable);selector.addState(new int[]{android.R.attr.state_selected}, selectDrawable);// 添加一个默认状态, 默认状态必须写在其他状态的最后面, 否则其他状态失效selector.addState(new int[]{}, defaultDrawable);return selector;}public static GradientDrawable getRoundRectDrawable(int radius, int color, boolean isFill, int strokeWidth){//左上、右上、右下、左下的圆角半径float[] radiusList = {radius, radius, radius, radius, radius, radius, radius, radius};GradientDrawable drawable = new GradientDrawable();drawable.setCornerRadii(radiusList);drawable.setColor(isFill ? color : Color.TRANSPARENT);drawable.setStroke(isFill ? 0 : strokeWidth, color);return drawable;}
//补充设置渐变色
public static GradientDrawable getRoundRectDrawable(int radius, int color, boolean isFill, int strokeWidth){//左上、右上、右下、左下的圆角半径float[] radiusList = {radius, radius, radius, radius, radius, radius, radius, radius};GradientDrawable drawable = new GradientDrawable();//设置渐变色,渐变方向从左上到右下,渐变颜色设置GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR,new int[]{R.color.blue_0B1152, R.color.blue_4E5988});drawable.setCornerRadii(radiusList);drawable.setColor(isFill ? color : Color.TRANSPARENT);drawable.setStroke(isFill ? 0 : strokeWidth, color);return drawable;}

亲测有效,写这篇文章只是想记录一下完整的实现代码。

相关博客推荐:

Android状态选择器selector的详细使用汇总

selector的两种设置方式

http://www.hengruixuexiao.com/news/55785.html

相关文章:

  • 怎么用群晖nas做网站链接买卖平台
  • 泌阳专业网站建设关键词推广计划
  • 网站视频播放代码网站排名优化培训哪家好
  • 设计素材网站0购物网站有哪些
  • 汕头市政府信息公开网宁波网站推广优化哪家正规
  • 网站软文怎么写seo自然优化排名技巧
  • 招工网站58同城google搜索中文入口
  • 什么网站可以兼职做平面设计关键词排名优化工具有用吗
  • 专为中年人做的的婚恋网站四川seo技术培训
  • 推荐几个好的seo网站程序模板2022拉新推广赚钱的app
  • 惠州做棋牌网站建设哪家好泉州百度推广排名优化
  • 如何制作网站首页快速的网站设计制作
  • 有什么免费开发网站建设软件有哪些优化设计七年级下册语文答案
  • 做教育行业网站微信最好用的营销软件
  • 建设安全监督站的网站上海网络推广外包
  • 做网站第一部优化大师哪个好
  • 用cms创建自己带数据库的网站和在本机搭建网站运行平台的心得体会百度指数关键词未收录怎么办
  • 服务器重启后网站打不开网络推广平台网站推广
  • 惠阳住房和建设局网站百度seo怎么优化
  • 网站建设愿景自己建网站怎么建
  • 公司网站开发款记什么科目如何引流推广
  • 做网站的公司现在还 赚钱吗6张家界seo
  • 香港公司能在国内做网站营销策划公司名称
  • 优秀的网站什么平台推广效果最好
  • 深圳较便宜的网站建设简述seo
  • 科技成果转化东莞网站seo公司
  • 为什么只有建设网站打不开黄页网站推广
  • 做企业网站要多长时间付费恶意点击软件
  • 做网站 怎么谈百度经验官方网站登录入口
  • 30岁学网站建设企业网站推广技巧