当前位置: 首页 > news >正文

wordpress新网站百度大搜是什么

wordpress新网站,百度大搜是什么,如何完整保存网站并做修改,小程序开发平台哪家好我将Android控件的Button和Checkbox的学习知识总结一下和大家共享 在Android开发中&#xff0c;按钮和复选框是非常常用的控件 Button控件的基本使用方法很简单&#xff0c;在布局文件中使用<Button>既可以了&#xff0c;或者在java代码&#xff1a;Button button &…

我将Android控件的Button和Checkbox的学习知识总结一下和大家共享

在Android开发中,按钮和复选框是非常常用的控件

Button控件的基本使用方法很简单,在布局文件中使用<Button>既可以了,或者在java代码:Button button = (Button)findViewById(R.id.button1);

Checkbox也是一样的。

1、Button控件

按钮控件的最常见的是单击事件,可以通过Button.setOnClickListener方法设置处理单机事件的监听器,也可以在<Button>标签的android:onClick属性指定单击事件方法名。如果当前类实现了android.view.view.OnClickListener接口,可以直接将this传入到setOnClickListener方法。

下面看例子:

布局文件:

<?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" android:gravity="center_horizontal"><Button android:id="@+id/btnCommonButton" android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="我的按钮1" /><Button android:id="@+id/btnImageButton"  android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="按钮"android:gravity="center" android:background="@drawable/button1" />
</LinearLayout>
java实现文件:

public class Main extends Activity implements OnClickListener, OnTouchListener,OnFocusChangeListener, OnKeyListener
{private int value = 1;private Button imageButton;private Button commonButton;private View lastFocusview;@Overridepublic void onClick(View view){Button button = (Button) view;if (value == 1&& button.getWidth() == getWindowManager().getDefaultDisplay().getWidth())value = -1;else if (value == -1 && button.getWidth() < 100)value = 1;button.setWidth(button.getWidth() + (int) (button.getWidth() * 0.1)* value);button.setHeight(button.getHeight() + (int) (button.getHeight() * 0.1)* value);}@Overridepublic boolean onKey(View view, int keyCode, KeyEvent event){ if (KeyEvent.ACTION_DOWN == event.getAction()){view.setBackgroundResource(R.drawable.button3);}else if (KeyEvent.ACTION_UP == event.getAction()){view.setBackgroundResource(R.drawable.button2);}return false;}@Overridepublic void onFocusChange(View view, boolean hasFocus){if (hasFocus){imageButton.setBackgroundResource(R.drawable.button2);}else{imageButton.setBackgroundResource(R.drawable.button1);}}@Overridepublic boolean onTouch(View view, MotionEvent event){if (event.getAction() == MotionEvent.ACTION_UP){view.setBackgroundResource(R.drawable.button1);}else if (event.getAction() == MotionEvent.ACTION_DOWN){view.setBackgroundResource(R.drawable.button2);}return false;}@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);commonButton = (Button) findViewById(R.id.btnCommonButton);imageButton = (Button) findViewById(R.id.btnImageButton);commonButton.setOnClickListener(this);imageButton.setOnClickListener(this);imageButton.setOnTouchListener(this);imageButton.setOnFocusChangeListener(this);imageButton.setOnKeyListener(this);}
}
也可以试试图文混排的按钮:

布局文件:

<?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"><LinearLayout android:orientation="horizontal"android:layout_width="fill_parent" android:layout_height="120dp"><Button android:layout_width="wrap_content"android:layout_height="wrap_content" android:drawableTop="@drawable/star" android:text="按钮1" /><Button android:layout_width="wrap_content"android:layout_height="wrap_content" android:drawableBottom="@drawable/star"android:text="按钮2" android:drawablePadding="30dp" /><Button android:layout_width="wrap_content"android:layout_height="wrap_content" android:drawableLeft="@drawable/star"android:text="按钮3" /><Button android:layout_width="wrap_content"android:layout_height="wrap_content" android:drawableRight="@drawable/star"android:text="按钮4" android:drawablePadding="20dp" /></LinearLayout><Button android:id="@+id/button" android:layout_width="200dp"android:layout_height="200dp" android:layout_marginTop="10dp"   />
</LinearLayout>
java实现文件:

public class Main extends Activity
{@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);Button button = (Button) findViewById(R.id.button);SpannableString spannableStringLeft = new SpannableString("left");Bitmap bitmapLeft = BitmapFactory.decodeResource(getResources(),R.drawable.image_left);ImageSpan imageSpanLeft = new ImageSpan(bitmapLeft, DynamicDrawableSpan.ALIGN_BOTTOM);spannableStringLeft.setSpan(imageSpanLeft, 0, 4,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);SpannableString spannableStringRight = new SpannableString("right");Bitmap bitmapRight = BitmapFactory.decodeResource(getResources(),R.drawable.image_right);ImageSpan imageSpanRight = new ImageSpan(bitmapRight);spannableStringRight.setSpan(imageSpanRight, 0, 5,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);button.append(spannableStringLeft);button.append("我的按钮");button.append(spannableStringRight);}
}
接下来介绍一下ImageButton图片按钮,其实和普通按钮一样,差别在与不用文本显示,而是图片:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal" android:layout_width="fill_parent"android:layout_height="fill_parent"><ImageButton android:layout_width="wrap_content"android:layout_height="wrap_content" android:src="@drawable/button1_1" /><ImageButton  android:layout_width="wrap_content"android:layout_height="wrap_content" android:src="@drawable/button2_1" />
</LinearLayout>
这边补充介绍RadioButton选项按钮控件和ToggleButton开关状态按钮控件
<pre name="code" class="html"><?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"><RadioGroup android:layout_width="wrap_content"android:layout_height="wrap_content"><RadioButton android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="选项1" /><RadioButton android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="选项2" /><RadioButton android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="选项3"android:drawableLeft="@drawable/star" android:drawableTop="@drawable/circle"android:drawableRight="@drawable/star" android:drawableBottom="@drawable/circle" android:drawablePadding="20dp" /></RadioGroup>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal" android:layout_width="fill_parent"android:layout_height="fill_parent"><ToggleButton android:layout_width="wrap_content"android:layout_height="wrap_content"/><ToggleButton android:id="@+id/toggleButton" android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_marginLeft="30dp"android:textOff="打开电灯" android:textOn="关闭电灯"  />
</LinearLayout>

 

2、Checkbox控件

Checkbox复选框控件,在这里采用动态加载的方式,在xml布局文件的根节点不仅可以像<LinearLayout>,<RelativeLayout>一样的ViewGroup,也可以直接使用View,下面采用Checkbox标签。

Checkbox.xml;

<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/checkbox" android:layout_width="fill_parent"android:layout_height="wrap_content" />

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/button" android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="确定" />
</LinearLayout>

java文件:

public class Main extends Activity implements OnClickListener
{private List<CheckBox> checkboxs = new ArrayList<CheckBox>();@Overridepublic void onClick(View view){String s = "";for (CheckBox checkbox : checkboxs){if (checkbox.isChecked())s += checkbox.getText() + "\n";}if ("".equals(s))s = "您还没选呢!";new AlertDialog.Builder(this).setMessage(s).setPositiveButton("关闭", null).show();}@Overridepublic void onCreate(Bundle savedInstanceState){String[] checkboxText = new String[]{ "是学生吗?", "是否喜欢Android?", "买车了吗?", "打算出国吗?" };super.onCreate(savedInstanceState);LinearLayout linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);for (int i = 0; i < checkboxText.length; i++){CheckBox checkbox = (CheckBox) getLayoutInflater().inflate(R.layout.checkbox, null);checkboxs.add(checkbox);checkboxs.get(i).setText(checkboxText[i]);linearLayout.addView(checkbox, i);}setContentView(linearLayout);Button button = (Button) findViewById(R.id.button);button.setOnClickListener(this);}
}


http://www.ritt.cn/news/18641.html

相关文章:

  • 12306网站是谁做的免费发帖论坛大全
  • 广州天河建站公司百度推广退款电话
  • 西宁网络公司网站制作企业网站设计模板
  • wordpress相册点击弹出框成都seo技术经理
  • 专业的网站建设服务商网站免费优化
  • 找公司做网站需要注意什么seo与sem的区别
  • 云南省保山建设网站网站开发公司排行榜
  • 给企业做网站收入在百度上怎么发布信息
  • 刚开始做网站要传数据库吗百度一下官方入口
  • 浙江备案需要开启网站吗优质外链
  • 按颜色分类的网页设计欣赏网站网络推广学校
  • 网站标题如何写重庆百度竞价开户
  • 怎么给网站添加代码如何营销
  • b2b电子商务网站开发网站快速优化排名app
  • 免费制作小说封面的网站国外网站排行
  • 网页设计与制作教程hbuilder长沙网站seo外包
  • 建一个网站花费百度上的广告多少钱一个月
  • wordpress同城插件seo网络培训
  • 谷歌上怎样做网站发帖推广哪个平台好
  • 景县做个油管的网站怎么做googlechrome浏览器
  • 目前市面上做网站的程序大数据获客系统
  • 全套商城网站后台管理系统网站管理页面百度搜索风云排行榜
  • 网站加速肇庆seo优化
  • 宁波seoseo方法培训
  • dede模板seo在线优化工具 si
  • 大学部门宣传视频创意南宁seo优化公司排名
  • 先建网站还是先做app好网络营销策划的内容
  • 深圳罗湖网站开发企业网站开发公司
  • 网站模板 金融优化营商环境个人心得
  • wordpress 调用自定义菜单长沙网址seo