Android开发---如何操作资源目录中的资源文件3--圆角边框、背景颜色渐变效果、边框颜色
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--圆角边框、背景颜色渐变效果、边框颜色的更多相关文章
- Android开发---如何操作资源目录中的资源文件4 ---访问xml的配置资源文件的内容
Android开发---如何操作资源目录中的资源文件4 XML,位于res/xml/,这些静态的XML文件用于保存程序的数据和结构. XmlPullParser可以用于解释xml文件 效果图: 描述: ...
- Android开发 ---如何操作资源目录中的资源文件2
Android开发 ---如何操作资源目录中的资源文件2 一.颜色资源管理 效果图: 描述: 1.改变字体的背景颜色 2.改变字体颜色 3.改变按钮颜色 4.图像颜色切换 操作描述: 点击(1)中的颜 ...
- Android开发---如何操作资源目录中的资源文件
效果图: 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...
- Android开发 ---如何操作资源目录中的资源文件5 ---Raw资源管理与国际化
效果图: 1.activity_main.xml 描述: 定义两个按钮,一个是Raw资源管理,一个是处理国际化语言,其中i18n表示简体中文 <?xml version="1.0&qu ...
- android开发之-查看、编辑手机sqlite数据库文件-实测
效果图: 1.开始——运行——输入cmd ,输入adb shell,错误:一是“adb不是内部命令或外部命令,也不是可运行的程序或批处理文件”,二是“error:device not found”. ...
- 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world
一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...
- 创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来
/*4.创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来*/ #import <Foundation/Foundation.h>#defin ...
- python实现在目录中查找指定文件的方法
python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...
- 如何查找一个目录中所有c文件的总行数
如何查找一个目录中所有c文件的行数 面试题问到了一题,如何统计wc文件夹下所有文件的行数,包括了子目录. 最后在 https://blog.csdn.net/a_ran/article/details ...
随机推荐
- delphi7产生条码
导读: 1 通过菜单”Component”下的”Import ActiveX”将“Microsoft Access Barcode Control 9.0”控件引入.这个控件(msbcode9.occ ...
- English trip V1 - B 1. How much is it? 它是多少钱? Teacher:Corrine Key: is/are
In this lesson you will learn to ask about prices. 本节课你将学习询问关于价格 课上内容(Lesson) one piece of two p ...
- Two Melodies CodeForces - 813D (DP,技巧)
https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...
- using强制对象清理资源 【转】
转 http://www.cnblogs.com/Legolas/p/detail-of-using.html using肯定所有人都用过,最简单的就是使用using引入命名空间,然后就是引入别名,简 ...
- JDK的bin目录下各种工具的使用说明_对不起自己,这么久没写博,抱歉
appletviewer.exe(小程序浏览器):一种执行HTML文件上的Java小程序类的Java浏览器 apt.exe:SolarisTM 操作系统和 Linux上用于处理注释的工具 extche ...
- SQL - 数据查询
数据查询是数据库的核心操作.SQL 提供了 select 语句进行数据查询,该语句的一般格式为: select [ ALL | distinct ] <目标列表达式> [ ,<目 ...
- 解决VS Code保存时候自动格式化
VS code 保存会自动格式化.以前都是alt+shift+F格式化的,现在一保存就格式化 解决方式:找到你的VScode扩展,把JS-CS-HTML Formatter这个插件禁用就可以解决
- [LeetCode] 94. Binary Tree Inorder Traversal(二叉树的中序遍历) ☆☆☆
二叉树遍历(前序.中序.后序.层次.深度优先.广度优先遍历) 描述 解析 递归方案 很简单,先左孩子,输出根,再右孩子. 非递归方案 因为访问左孩子后要访问右孩子,所以需要栈这样的数据结构. 1.指针 ...
- win10打文件预览功能
- shell 数值运算
declare数值运算 linux默认变量类型为字符串 declare [+/-] [选项] 变量名 '-' 给变量设定类型属性 '+' 取消变量的类型属性 '-a' 将变量声明为数组型 '-i' 将 ...