Android开发---如何操作资源目录中的资源文件3

效果图

  1、圆角边框

  2、背景颜色渐变效果

  

1、activity_main.xml

  描述:

    定义了一个shape资源管理按钮

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Shape资源管理"
android:onClick="test_3"
/>
</LinearLayout>

2、MainActivity.java

描述:

  页面跳转

package com.example.android_shaperesoucesdemo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void test_3(View view){
Intent intent = new Intent(this,ShapeActivity.class);
startActivity(intent);
}
}

3、activity_shape.xml

  描述:

    1、定义了一个文本输入框和一个按钮

    2、其中文本输入框通过android:background="@drawable/back_shape_solid"引入back_shape_solid.xml中定义的资源,设置背景填充色为白色、边框颜色为绿色、边框为圆角、内边距

    3、其中按钮通过android:background="@drawable/button_back_color"引入button_back_color.xml中定义的资源,没点击按钮前填充色为蓝色、边框颜色为绿色、圆角,当点击时,边框颜色变为红色,圆角,背景色从左往右由绿色变为红色

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_shape"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用户名:"
android:textSize="25dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/uname"
android:background="@drawable/back_shape_solid"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_back_color"
android:text="按钮渐变背景"
/>
</LinearLayout>

4、ShapeActivity.java

  描述:

    无操作

package com.example.android_shaperesoucesdemo;

import android.app.Activity;
import android.os.Bundle; public class ShapeActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shape);
}
}

5、res资源目录下drawable包中创建一个back_shape_solid.xml文件

back_shape_solid.xml

   描述:

     设置了文本框的背景填充色、边框颜色、圆角、边距

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--整个UI的背景填充色-->
<solid android:color="@android:color/white"/>
<!--描边android:dashGap="10sp"
android:dashWidth="5dp"-->
<stroke android:color="@color/navicat_color"
android:width="2dp"/>
<!--圆角-->
<corners android:radius="15dp"/>
<!--内容和边框间距-->
<padding android:bottom="0dp" android:left="0dp"/>
</shape>

6、res资源目录下drawable包中创建一个button_back_color.xml文件

button_back_color.xml

  描述:

    设置了按钮的填充色、边框、圆角、背景色渐变效果

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape>
<!--填充色-->
<solid android:color="@color/colorPrimary"/>
<!--描边-->
<stroke android:color="@color/navicat_color"
android:width="3dp"/>
<!--圆角-->
<corners android:radius="5dp"/>
</shape>
</item>
<item android:state_pressed="true">
<shape>
<!--描边-->
<stroke android:color="@color/colorAccent"
android:width="3dp"/>
<!--圆角-->
<corners android:radius="5dp"/>
<!--渐变背景色-->
<gradient android:startColor="@color/navicat_color"
android:endColor="@color/colorAccent"
android:gradientRadius="3000"/>
</shape>
</item>
</selector>

7、res资源目录下values包中修改colors.xml文件

  colors.xml 

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="navicat_color">#63CF10</color>
</resources>

Android开发---如何操作资源目录中的资源文件3--圆角边框、背景颜色渐变效果、边框颜色的更多相关文章

  1. Android开发---如何操作资源目录中的资源文件4 ---访问xml的配置资源文件的内容

    Android开发---如何操作资源目录中的资源文件4 XML,位于res/xml/,这些静态的XML文件用于保存程序的数据和结构. XmlPullParser可以用于解释xml文件 效果图: 描述: ...

  2. Android开发 ---如何操作资源目录中的资源文件2

    Android开发 ---如何操作资源目录中的资源文件2 一.颜色资源管理 效果图: 描述: 1.改变字体的背景颜色 2.改变字体颜色 3.改变按钮颜色 4.图像颜色切换 操作描述: 点击(1)中的颜 ...

  3. Android开发---如何操作资源目录中的资源文件

    效果图: 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...

  4. Android开发 ---如何操作资源目录中的资源文件5 ---Raw资源管理与国际化

    效果图: 1.activity_main.xml 描述: 定义两个按钮,一个是Raw资源管理,一个是处理国际化语言,其中i18n表示简体中文 <?xml version="1.0&qu ...

  5. android开发之-查看、编辑手机sqlite数据库文件-实测

    效果图: 1.开始——运行——输入cmd ,输入adb shell,错误:一是“adb不是内部命令或外部命令,也不是可运行的程序或批处理文件”,二是“error:device not found”. ...

  6. 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world

    一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...

  7. 创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来

    /*4.创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来*/ #import <Foundation/Foundation.h>#defin ...

  8. python实现在目录中查找指定文件的方法

    python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...

  9. 如何查找一个目录中所有c文件的总行数

    如何查找一个目录中所有c文件的行数 面试题问到了一题,如何统计wc文件夹下所有文件的行数,包括了子目录. 最后在 https://blog.csdn.net/a_ran/article/details ...

随机推荐

  1. python paramiko自动登录网络设备抓取配置信息

    ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(hostn ...

  2. DPDK 16.04/16.11.2 默认tx offload是关闭的引起tx vlan offload无效

    打开IXGBE调试日志发发现:tx使用ixgbe_xmit_pkts_vec,默认tx offload无效了PMD: ixgbe_set_tx_function(): Using simple tx ...

  3. fedora21 中lamp的搭建(测试没有问题)

    LAMP Stands for Linux,Apache,MySQL and PHP. Most of the websites works with the above combination. T ...

  4. Confluence 6 修改导航显示选项

    选择 子页面(Child pages)来在边栏中查看当前页面的子页面. 选择 页面树(Page tree)来查看整个空间的页面树,扩展当前的页面. 你也可以选择是否完全隐藏导航显示选项或者添加你希望可 ...

  5. Vue.js,select中的option用ajax想循环控制值的显示 v-model可以实现但提示报错,这是为什么?

    应该将v-model换成:value,因为v-model只能绑定一个值,无法绑定多个值 <select v-model="citys">       <optio ...

  6. SQL 2016安装

    微软数据库SQL Server 2016正式版在2016年6月就发布,由于近期工作忙,一直拖到现在才有时间把安装过程写到博客上,分享给大家.本人一直习惯使用英文版,所以版本和截图都是英文版的.废话少说 ...

  7. SpringMVC的底层实现

    SpringMVC的底层实现流程: SpringMVC的核心是DispatchServlet,它负责接收HTTP的请求和协调SpringMVC中各个组件来完成请求处理的任务,一个请求被截获后,Disp ...

  8. python第三方库scrapy框架的安装

    1.确认python和pip安装成功 2.安装win32py          提供win32api,下载地址:https://sourceforge.net/projects/pywin32/fil ...

  9. 在MongoDB中执行查询、创建索引

    1. MongoDB中数据查询的方法 (1)find函数的使用: (2)条件操作符: (3)distinct找出给定键所有不同的值: (4)group分组: (5)游标: (6)存储过程. 文档查找 ...

  10. ActiveMQ producer不断发送消息,会导致broker内存耗尽吗?

    http://activemq.apache.org/my-producer-blocks.html 回答了这个问题: ActiveMQ 5.x 支持Message Cursors,它默认把消息从内存 ...