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

设计网站推荐提升审美上海谷歌优化

设计网站推荐提升审美,上海谷歌优化,中文wordpress站点,重庆那些公司的网站是网易做的最近在做一个使用接口返回的字符串:"#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.dinnco.com/news/75251.html

相关文章:

  • 网站建设案例咨询推广获客
  • asp网站制作软件百度提交入口
  • 网站ie兼容性软文
  • 网站优化要从哪些方面做seo服务商
  • 分类信息网站开发网站推广的基本方法
  • 网站seo 优化关键词你们懂的
  • 公司网站建设准备资料网站优化包括
  • 上海比较好的网站建设公司最全bt磁力搜索引擎索引
  • 网络管理系统逻辑模型seo公司怎么推广宣传
  • WordPress给编辑器站长工具seo查询5g5g
  • 类似非小号的网站怎么做站长统计app下载免费
  • 南宁百度seo价格厦门seo优化推广
  • 南京建设局网站首页公司网站设计需要多少钱
  • 怎么用群晖nas做网站厦门seo代运营
  • 同城配送网站建设搜索引擎优化seo培训
  • 网站图解图片是用什么软件做的app渠道推广
  • 什么网站做弹窗广告好网络推广外包搜索手机蛙软件
  • 武进区住房和城乡建设局网站微信营销策略
  • java做的网站很快抖音搜索seo代理
  • 网站建设销售怎么样seo建设招商
  • 沧州网站建设的公司莫停之科技windows优化大师
  • 湘西北京网站建设关注公众号一单一结兼职
  • 广州市建设交易中心网站首页短视频营销推广方式
  • php和java做网站哪个简单点链网
  • 网站优化成功案例如何免费搭建自己的网站
  • 国外公司网站模板网络营销比较成功的企业
  • 路由器做网站80端口高报师培训机构排名
  • 网站建设栏目管理口碑营销案例及分析
  • 找合伙人的网站做淘宝郑州网站优化seo
  • 在线免费网站建设平台企业网络营销青岛