Button的使用(十二):改变按钮的高度和字体颜色
2014-04-02 20:06
483 查看
package com.example.androidtest; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.graphics.Color; import android.widget.Button; public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button button = (Button)findViewById(R.id.testButton); final Button chageButton = (Button)findViewById(R.id.layoutButton); chageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub changeOption(button); } }); final Button changeButton2 = (Button)findViewById(R.id.textColorButton); changeButton2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { changeOption2(button); } }); } public void changeOption(Button button) { if (button.getHeight() == 100) { button.setHeight(30); } else { button.setHeight(100); } } public void changeOption2(Button button) { button.setTextColor(Color.RED); } }activiy_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/testButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is the test Button"/> <Button android:id="@+id/layoutButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Change Layout"/> <Button android:id="@+id/textColorButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Change Text Color"/> </LinearLayout>
相关文章推荐
- 改变 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景
- 在xml文件中控制字体颜色随着按钮状态改变
- Android 使用selector设置button字体颜色无效
- C#button之怎样点击按钮使之循环改变背景颜色
- 改变UIALertView中button的字体颜色
- JAVASCRIPT通过点击按钮来改变字体颜色
- 鼠标放在button按钮颜色改变、、input按钮怎么添加超链接
- 使用Selector改变TextView的字体颜色textColor的方法
- 设置button按钮背景色,及字体的颜色
- 改变 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景
- MFC中CMFCButton类改变颜色的使用
- ZTREE通过外部按钮动态改变树节点字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- 用代码改变按钮字体的颜色
- 改变 自绘 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景及其动态创建中的问题
- [转]改变 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景
- UINavigationcontrollerBar,UIbarButtonItem按钮以及backButton背景及背景颜色改变
- android中使用selector选择器改变字体颜色
- android 按钮按下时改变字体颜色
- iOS使用NSMutableAttributedString改变字符串中部分文字的字体颜色或大小