大家好,今天我们来说下怎样做button的半透明背景效果!很简单的!
首先,给大家贴上main.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/bg"><!--android:background="@drawable/bg这里为了增强对比度才用的我资源中的一个图片-->
<Button
android:background="@drawable/ic_launcher"
android:layout_width="300dip"
android:layout_height="200dip"
android:textColor="#fff"
android:text="button半透明背景"
android:id="@+id/button1"
/>
</LinearLayout>
然后,给大家贴上java代码:
package com.guo.myGridView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class MyGridViewTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.button1);;
b.getBackground().setAlpha(35);//这里利用阿尔法滤镜设置button背景的透明度
}
}
ok了!运行吧!