Android基础TOP5_4:点击按钮更换样式,设置透明度
在res/drawable创建两个样式 点击前/点击后

round:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--设置渐变颜色 angle=""是从左到右 90是从上到下 180是从右到左 -->
<gradient
android:startColor="#4169E1"
android:endColor="#E6E6FA"
android:angle="" />
<stroke
android:width="2dp"
android:color="#D2691E"
/>
<corners android:radius="10dip"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
newround:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- angle=""是从左到右 90是从上到下 180是从右到左 且必须是45的倍数 -->
<gradient
android:startColor="#FFD700"
android:endColor="#f5deb3"
android:angle="" />
<stroke
android:width="2dp"
android:color="#FFB6C1"
/>
<corners android:radius="20dip"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
接下来j
Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/asdf"
tools:context="com.example.top5_4.MainActivity" > <Button
android:id="@+id/but"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="点击按钮改变按钮样式"
android:background="@drawable/round"
/>
</LinearLayout>
JAVA:
public class MainActivity extends Activity {
private Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but=(Button) findViewById(R.id.but);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//点击后更改按钮样式
but.setBackgroundResource(R.drawable.newround);
//另外设置按钮的透明度setAlpha()里面的值大小为0~255
but.getBackground().setAlpha();
}
});
}
}
运行效果:
点击之前

点击后:

Android基础TOP5_4:点击按钮更换样式,设置透明度的更多相关文章
- Python3 tkinter基础 Menubutton 点击按钮出现下拉菜单
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 记录--前端 页面 jquery 被点击按钮修改样式 其他默认
jquery实现页面条件筛选 此功能类似淘宝的条件筛选,主要是页面样式的更改,问了大神也磨磨唧唧了很久才搞定0.0.... 先贴代码..... 代码知识有 border-radius 设置圆角边框 s ...
- Android基础TOP2:单机按钮改变字体颜色
---恢复内容开始--- Activity: <TextView android:id="@+id/t1" android:textSize="30dp" ...
- Android开发案例 点击按钮出现 简易的消息提示框
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 进阶实战 css 点击按钮的样式
1. html结构 <div class="menu-wrap"> <input type="checkbox" class="t ...
- 【Android基础】点击Back键退出应用程序
//第一种方法(弹出对话框) @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-genera ...
- Python3 tkinter基础 OptionMenu 点击按钮,出现单选的下拉列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- cocos creator按钮点击按钮弹起效果设置方法
如图所示: 只要设置下button的Transition的属性为Scale即可,参数自己调整下.
- vue踩坑之路--点击按钮改变div样式
有时候,我们在做项目的时候,想通过某个按钮来改变某个div样式,那么可以通过以下代码实现: <!DOCTYPE html> <html> <head> <me ...
随机推荐
- jquery校验框架
http://www.validform.club/ http://craftpip.github.io/jquery-confirm/
- jquery datatable显示隐藏子表
<table id="parentTable"> <thead> <tr> <th> ...
- [TypeScript] Overload a Function with TypeScript’s Overload Signatures
Some functions may have different return types depending on the types of the arguments with which th ...
- cocos2d-x中绘制3D图形--3D ToolKit for cocos2dx实现原理
首先:了解具体情况请看这里:https://github.com/wantnon2/3DToolKit-for-cocos2dx 在看代码之前,最好还是先把项目git下来执行一下demoproject ...
- 2011 ACM-ICPC 成都赛区A题 Alice and Bob (博弈动规)
题目大意: 有K堆石子,每堆有Ki个.两人的操作能够是: 1 从某一堆拿走一个 假设该堆在此之后没有石子了.就消失 2 合并两个堆 求是否 ...
- Kernel Live-patching (by quqi99)
作者:张华 发表于:2016-02-27 版权声明:能够随意转载.转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) GC ...
- jquery-mobile 学习笔记之中的一个(基础属性)
写在前面 本文是依据w3c 学习轨迹,自己研习过程中记录下的笔记,仅仅供自己学习轨迹记录之用,不喜勿喷. 0 引入库 引入相应的文件: <link rel="stylesheet&qu ...
- python 矩阵
python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入numpy的包. 1.numpy的导入和使用 from numpy import *;#导入numpy的库函数 im ...
- [JSOI 2016] 灯塔
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4850 [算法] 首先对不等式进行移项 : hj <= hi + p - sqr ...
- [Jsoi2015]字符串树
https://www.zybuluo.com/ysner/note/1298148 题面 字符串树本质上还是一棵树,即\(N\)个节点\(N-1\)条边的连通无向无环图,节点 从\(1\)到\(N\ ...