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

网站制作都包括什么烟台网站建设4038gzs

网站制作都包括什么,烟台网站建设4038gzs,制作小程序公司,php 网站 上传到空间最近在做一个使用接口返回的字符串:"#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.yayakq.cn/news/151056/

相关文章:

  • 做兼职拍照片传网站宁波网站建设速成
  • 比较出名的网站域名网站建设大忌
  • 珠海网站开发哪家好opencart 构建电子商务网站
  • 如何用织梦做网站详细教程网站制作公司司
  • 直接通过ip访问网站标签化网站
  • 中江门户网站石家庄建站模板
  • wordpress网站统计代码放哪个文件网站热力图工具
  • 四川省建设厅注册管理中心网站wordpress 是免费的吗
  • 建设网站如何进行网站备案做移动网站优
  • 莆田网站建设方案优化vs网站开发效果图
  • 网站设计公司名称WordPress开启me
  • 久其软件公司网站东京购物商城
  • 合肥能做网站的公司在网上做软件挣钱的网站
  • 建设短视频网站开发电商平台多少钱
  • 汽车用品网站建设网站标题前的小图标怎么做
  • 网站建设通俗讲南宁网站建设活动
  • 西安哪家网站做的好上海网站建设开发哪
  • sql 新建网站微信公众号app下载安装
  • 焦作建设银行网站xd网页设计教程
  • 外贸工具大全网站电子商务教材电子版
  • 网站如何防止别人抄袭在线制作印章diy印章
  • 襄阳php网站开发无锡网站制作难吗
  • 请别人做网站如何交付久久建筑网西瓜视频
  • 自己做手机版网站制作网页游戏开服表就找新壹玩
  • 网站问答平台推广方案忻州做网站公司
  • 公司部门职能介绍网络seo首页
  • 做网站网站wordpress 上传文件路径
  • 高端网站制作网址天津北京网站建设
  • 网站建设时间表公司网站开发费用怎么做账
  • 网站建设参考书504 wordpress