在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:点击按钮更换样式,设置透明度的更多相关文章

  1. Python3 tkinter基础 Menubutton 点击按钮出现下拉菜单

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. 记录--前端 页面 jquery 被点击按钮修改样式 其他默认

    jquery实现页面条件筛选 此功能类似淘宝的条件筛选,主要是页面样式的更改,问了大神也磨磨唧唧了很久才搞定0.0.... 先贴代码..... 代码知识有 border-radius 设置圆角边框 s ...

  3. Android基础TOP2:单机按钮改变字体颜色

    ---恢复内容开始--- Activity: <TextView android:id="@+id/t1" android:textSize="30dp" ...

  4. Android开发案例 点击按钮出现 简易的消息提示框

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  5. 进阶实战 css 点击按钮的样式

    1.  html结构 <div class="menu-wrap"> <input type="checkbox" class="t ...

  6. 【Android基础】点击Back键退出应用程序

    //第一种方法(弹出对话框) @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-genera ...

  7. Python3 tkinter基础 OptionMenu 点击按钮,出现单选的下拉列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. cocos creator按钮点击按钮弹起效果设置方法

    如图所示: 只要设置下button的Transition的属性为Scale即可,参数自己调整下.

  9. vue踩坑之路--点击按钮改变div样式

    有时候,我们在做项目的时候,想通过某个按钮来改变某个div样式,那么可以通过以下代码实现: <!DOCTYPE html> <html> <head> <me ...

随机推荐

  1. sqlalchemy多表联合查询的左连接、右连接等使用

    #按用户名摸糊查询trans_details.query.join(Uses).filter(Users.username.like('%xx%'))#select xxx from trans_de ...

  2. Myeclipse的优化方法

    近期在实习,公司给分配了新的电脑,可是不知道怎么弄得,总是弄得非常卡,没办法仅仅有自己好好整理一下电脑了,另外.为了提高编程的效率.顺便也把Myeclipse也优化了一下. 第一步: 取消自己主动va ...

  3. hdu1863

    #include<cstdio> #include<algorithm> using namespace std; int N,M; struct edge { int u,v ...

  4. WCC框架设计

    一个好的框架,不仅能帮助程序开发节约很多时间,同时也能减少bug的引入.这个框架是在ssy同学的基础上进行了一些改进: 主要在于一下几点(会随着项目开发逐渐更新这篇文章) 1. 应用了反射机制,实现网 ...

  5. 【bzoj4604】The kth maximum number

    暴力 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> ...

  6. Android开发之接收系统广播消息

    BroadcastReceiver除了接收用户所发送的广播消息之外.另一个重要的用途:接收系统广播. 假设应用须要在系统特定时刻运行某些操作,就能够通过监听系统广播来实现.Android的大量系统事件 ...

  7. HDU5768Lucky7

    Lucky7 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  8. POJ1743 Musical Theme 最长重复子串 利用后缀数组

    POJ1743 题目意思是求不重叠的最长相同变化的子串,输出该长度 比如1 2 3 4 5 6 7 8 9 10,最长长度为5,因为子串1 2 3 4 5 和 6 7 8 9 10变化都一样的 思路: ...

  9. SVN工具使用技巧

    SVN打tag SVN打tag是一个很常用的功能,要谈打tag,还得从SVN官方推荐的目录结构说起.SVN官方推荐在一个版本库的根目录下先建立trunk.branches.tags这三个文件夹,其中t ...

  10. uva11542

    https://vjudge.net/problem/UVA-11542 xor高斯消元... 答案为2^f-1 其实书上有一个问题 样例有3种情况,其中4,6,15是绑在一起的,也就是他们必须满足一 ...