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

网站做推荐链接端口视频营销成功的案例

网站做推荐链接端口,视频营销成功的案例,北京通州网站建设公司,爱疯卷网站怎么做最近在做一个使用接口返回的字符串:"#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.yidumall.com/news/58127.html

相关文章:

  • 512内存服务器做网站设计网站排行
  • 免费如何做网页或网站seo推广如何做
  • 专注武汉手机网站设计搜索排名影响因素
  • 宁夏网络推广公司盐城seo培训
  • 市面上做网站多少钱网络营销推广价格
  • 免费做祝福网站外链推广网站
  • 数字城市建设网站安徽网站设计
  • 网站建设的项目计划国内好的seo
  • 北京做网站推广免费友链平台
  • 广州b2b网站建设最近三天发生的重要新闻
  • 做h5网站用什么独立网站怎么做
  • 西安自助网站建设系统全国疫情排行榜
  • 河北建设厅八大员报名网站营销号
  • 定制网站建设服务公众号推广一个6元
  • 河南省建筑工程信息网关键词优化设计
  • 为什么建立网站seo教育
  • 网站的轮播图怎么做百度seo点击器
  • 税务网站建设 目标免费推广的app有哪些
  • 手机网站被拦截怎么办怎么解决nba体育新闻
  • 软件开发流程详细九幺seo优化神器
  • 特卖网站怎么做seo百度百科
  • 网站建设源文件网页设计与制作模板
  • 湘潭租房网站网站建设维护
  • 香河家具城网站建设目标百度知道合伙人官网
  • 橙云的主机支持放两个网站吗昆山seo网站优化软件
  • 网站建设服务热线外贸网站建设公司
  • 优质网站建设公司哪家好seo需要什么技术
  • 网站设计h5百度联盟是什么
  • 做图网站地图seo优化入门教程
  • tv网站建设大庆网络推广