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. C#中读取xml文件指定节点

    目录(?)[-] XmlDocumentSelectSingleNode方法的使用 XmlDocumentSelectNodes方法的使用 通过节点属性查找指定节点   参考:Select XML N ...

  2. 如何启动iis(Internet 信息服务(IIS)管理器)

    Internet 信息服务(IIS)管理器 启动 IIS 管理器1.从“开始”菜单,指向“管理工具”,然后单击“Internet 信息服务 (IIS) 管理器”. 从“运行”对话框启动 IIS 管理器 ...

  3. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: ..... this is incompatible with sql_mode=only_full_group_by

    一.异常信息 org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysq ...

  4. Practical Node.js (2018版) 第5章:数据库 使用MongoDB和Mongoose,或者node.js的native驱动。

    Persistence with MongoDB and Mongoose https://github.com/azat-co/practicalnode/blob/master/chapter5/ ...

  5. Build Castles(构建城堡)

    Charlemagne, the King of Frankie, 英文描述 请参考图片中的说明. 中文描述 根据给出的数组确定能够盖多少城堡. 思路和点评 我不能确定我的思路是正确的,也欢迎大家参与 ...

  6. 从早期 Spring Boot 版本升级

    如果你现在正在从早期的 Spring Boot 版本进行升级的话,请访问 “migration guide” on the project wiki 页面,这个页面提供了有关升级的详细指南.同时也请查 ...

  7. Centos 6.5 搭建阿里云yum源

    Linux系统下yum源配置(Centos 6) 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo ...

  8. laravel的重定向

    Route::get("redirect1", function () { // redirct的三种写法 // return redirect()->route(" ...

  9. 『MXNet』第六弹_Gluon性能提升

    一.符号式编程 1.命令式编程和符号式编程 命令式: def add(a, b): return a + b def fancy_func(a, b, c, d): e = add(a, b) f = ...

  10. Shiro中Realm

    6.1 Realm [2.5 Realm]及[3.5 Authorizer]部分都已经详细介绍过Realm了,接下来再来看一下一般真实环境下的Realm如何实现. 1.定义实体及关系   即用户-角色 ...