首页 文章 精选 留言 我的

精选列表

搜索[check],共4550篇文章
优秀的个人博客,低调大师

23.1. php function check

#!/bin/bash LOGFILE=/tmp/my.log echo > $LOGFILE for helper in `ls -1 class/helper/` do echo ========================== $helper ============================ >> $LOGFILE class=`grep '^class' class/helper/$helper | awk -F ' ' '{print $2}'` for fun in `grep 'public function [a-zA-Z]' class/helper/$helper | awk -F ' ' '{print $3}' | awk -F '(' '{print $1}'` do count=`grep -r "$class->$fun(" *|wc -w` if [ $count == 0 ]; then echo "[ unused ] $class->$fun" >> $LOGFILE else echo "[ used ] $class->$fun" >> $LOGFILE fi echo "[`date`] [$helper] $class->$fun (checked: $count)" done done 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

优秀的个人博客,低调大师

Android--UI之Radio、Check、Toggle

前言 这篇博客讲解一下Android平台下,RadioButton、CheckBox以及ToggleButton三个控件的用法,因为这三个控件之中都存在一个选中或是没选中的状态,所以放在一起讲解。 这三个控件均是从Button之中间接继承而来的,所以一些Button中的设置都是通用的,如图文混排,动态修改显示内容,因为之前已经对这些内容进行了说明,如果不清楚朋友可以参见一下我的另外一篇博客,Android—UI之Button,所以这篇博客只是就这三个控件的常用方法进行简要说明,并给出示例。 CompoundButton RadioButton(单选按钮)、CheckBox(复选按钮)、ToggleButton(开关按钮)都继承自android.widget.CompoundButton类,而CompoundButton又继承自Button类,在这个类中封装了一个checked属性,用于判断是否被选中,这也是它与Button的不同,对其进行了扩展,这个属性在这三个控件中的用法是一样的。 一般checked属性通过以下方式来设置与获取: android:checked/setChecked(boolean):设置是否被选中。 isChecked():获取是否被选中。 RadioButton RadioButton,为一个单选按钮,一般配合RadioGroup一起使用,在同一RadioGroup内,所有的RadioButton的选中状态为互斥,它们有且只有一个RadioButton被选中,但是在不同的RadioGroup中是不相互影响的。 下面通过一个简单的示例来说明一下,在示例中会存在两个RadioButton,用于定义性别信息,当用户选中了某个后,点击按钮,把选中的信息提示到屏幕上。 布局代码: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <TextView 8 android:layout_width="fill_parent" 9 android:layout_height="wrap_content" 10 android:text="Gender:" /> 11 <!-- 定义一个RadioGroup用于包装RadioButton --> 12 <RadioGroup 13 android:id="@+id/gender" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" > 16 17 <RadioButton 18 android:layout_width="wrap_content" 19 android:layout_height="wrap_content" 20 android:text="male" /> 21 22 <RadioButton 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:text="female" /> 26 </RadioGroup> 27 28 <Button 29 android:id="@+id/btnGender" 30 android:layout_width="fill_parent" 31 android:layout_height="wrap_content" 32 android:text="选择性别" /> 33 34 </LinearLayout> 实现代码: 1 package com.example.changebutton; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.widget.Button; 7 import android.widget.RadioButton; 8 import android.widget.RadioGroup; 9 import android.widget.Toast; 10 11 public class RadioButtonActivity extends Activity { 12 private RadioGroup group; 13 private Button btnGender; 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 // TODO Auto-generated method stub 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.radiobutton_layout); 20 21 group = (RadioGroup) findViewById(R.id.gender); 22 btnGender = (Button) findViewById(R.id.btnGender); 23 btnGender.setOnClickListener(new View.OnClickListener() { 24 @Override 25 public void onClick(View v) { 26 // 获取单选按钮的选项个数 27 int len = group.getChildCount(); 28 String msgString = ""; 29 for (int i = 0; i < len; i++) { 30 //RadioGroup中包含的子View就是一个RadioButton 31 RadioButton radiobutton = (RadioButton) group.getChildAt(i); 32 if (radiobutton.isChecked()) { 33 //如果被选中,则break循环,并且记录选中信息 34 msgString = "You choose to be a " 35 + radiobutton.getText().toString(); 36 break; 37 } 38 } 39 if (msgString.equals("")) { 40 Toast.makeText(RadioButtonActivity.this, 41 "Please select a gender!", Toast.LENGTH_SHORT) 42 .show(); 43 } else { 44 Toast.makeText(RadioButtonActivity.this, msgString, 45 Toast.LENGTH_SHORT).show(); 46 } 47 } 48 }); 49 } 50 } 实现效果: CheckBox CheckBox是一个复选按钮,它的用法与RadioButton很像,但是与之不同的是,它可以多选,所以也无需用一个组控件包裹起来。 这里涉及了一动态添加UI控件的知识,在Android中动态增加控件一般有两种方式: 为需要操作的UI控件指定android:id属性,并且在Activity中通过setContentView()设置需要查找的布局文件。这样才可以在Activity中,使用findViewById(int)方法找到待操作的控件。 为需要操作的UI控件单独创建XML文件,在Activity中使用动态填充的方式:getLayoutInflater().inflate(int)的方式获取到XML文件定义的控件。 这里通过一个示例来说明CheckBox的使用,在示例中动态添加了CheckBox的选项,并且对其进行选中之后提示选中信息。上面两种方式都用用到,通过一个chooseMethod(boolean)区分。 布局代码: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 android:id="@+id/checkLayout"> 7 <!-- 这里只是定义了一个按钮,其他的CheckBox控件在代码中动态添加 --> 8 <Button 9 android:id="@+id/checkBtn" 10 android:layout_width="fill_parent" 11 android:layout_height="wrap_content" 12 android:text="确定" /> 13 14 </LinearLayout> 如果使用动态填充的方式获取CheckBox的话,需要添加一个CheckBox的XML文件,代码如下: 1 <?xml version="1.0" encoding="utf-8"?> 2 <CheckBox xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" > 5 </CheckBox> 实现代码: 1 package com.example.changebutton; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import android.app.Activity; 6 import android.app.AlertDialog; 7 import android.os.Bundle; 8 import android.view.View; 9 import android.view.View.OnClickListener; 10 import android.widget.Button; 11 import android.widget.CheckBox; 12 import android.widget.LinearLayout; 13 14 public class CheckBoxActivity extends Activity implements OnClickListener { 15 16 private List<CheckBox> checkBoxs = new ArrayList<CheckBox>(); 17 private Button checkBtn; 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 chooseMethod(false); 23 checkBtn = (Button) findViewById(R.id.checkBtn); 24 checkBtn.setOnClickListener(this); 25 } 26 27 @Override 28 public void onClick(View v) { 29 String s = ""; 30 //循环cheackBoxs 31 for (CheckBox c : checkBoxs) { 32 if (c.isChecked()) { 33 //如果选中就添加选中结果到msg中。 34 s += c.getText() + "\n"; 35 } 36 } 37 if ("".equals(s)) { 38 s = "您没有选中选项!"; 39 } 40 //使用对话框弹出选中的信息 41 new AlertDialog.Builder(this).setMessage(s) 42 .setPositiveButton("Exit", null).show(); 43 } 44 45 private void chooseMethod(boolean b) { 46 String[] checkboxText = new String[] { "You are student?", 47 "Do you like Android?", "Do you have a girlfriend", 48 "Do you like online shopping?" }; 49 if (b) { 50 //使用本文中提到的第一种方式,通过Id动态加载 51 setContentView(R.layout.checkbox_layout); 52 //获取带填充的布局控件 53 LinearLayout linearLayout = (LinearLayout) this 54 .findViewById(R.id.checkLayout); 55 //根据数组,循环添加内容 56 for (int i = 0; i < checkboxText.length; i++) { 57 CheckBox checkbox = new CheckBox(this); 58 checkBoxs.add(checkbox); 59 checkBoxs.get(i).setText(checkboxText[i]); 60 //把CheckBox加入到布局控件中 61 linearLayout.addView(checkbox); 62 } 63 } else { 64 //通过动态填充的方式,找到布局文件 65 LinearLayout linearLayout = (LinearLayout) getLayoutInflater() 66 .inflate(R.layout.checkbox_layout, null); 67 for (int i = 0; i < checkboxText.length; i++) { 68 //在通过动态填充的方式找到CheckBox的文件 69 CheckBox checkbox = (CheckBox) getLayoutInflater().inflate( 70 R.layout.cheackbox, null); 71 checkBoxs.add(checkbox); 72 checkBoxs.get(i).setText(checkboxText[i]); 73 linearLayout.addView(checkbox); 74 } 75 //最后把这个布局文件加载显示 76 setContentView(linearLayout); 77 } 78 } 79 } 实现效果 ToggleButton ToggleButton,一个开关按钮,有两个状态,大抵的用法与上面两个控件一直,可以通过两个属性显示不同状态时,控件内显示文字的内容不同,属性如下: android:textOff/setTextOff(CharSequence):设置关闭时显示内容。 android:textOn/setTextOn(CharSequence):设置打开时显示内容。 ToggleButton,这个控件有一个OnCheckedChangeListener()事件,当开关的状态切换的时候会被触发,其中需要传递一个OnCheckedChangeListener接口的实现内,当被切换时,触发其中的onCheckedChange()方法,可以在其中写需要实现的功能代码。 下面通过一个示例讲解一下ToggleButton的使用,使用一个toggleButton控件,控制一个LinearLayout的布局排列方式。 布局代码: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <ToggleButton 8 android:id="@+id/togBtn" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:checked="true" 12 android:textOff="横向排列" 13 android:textOn="纵向排列" /> 14 15 <LinearLayout 16 android:id="@+id/OriLayout" 17 android:layout_width="match_parent" 18 android:layout_height="match_parent" 19 android:orientation="vertical" > 20 21 <Button 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:text="btn1" /> 25 26 <Button 27 android:layout_width="wrap_content" 28 android:layout_height="wrap_content" 29 android:text="btn2" /> 30 31 <Button 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:text="btn3" /> 35 </LinearLayout> 36 37 </LinearLayout> 实现代码: 1 package com.example.changebutton; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.CompoundButton; 6 import android.widget.CompoundButton.OnCheckedChangeListener; 7 import android.widget.LinearLayout; 8 import android.widget.ToggleButton; 9 10 public class ToggleButtonActivity extends Activity { 11 private ToggleButton togBtn; 12 private LinearLayout linearLayout; 13 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 // TODO Auto-generated method stub 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.toggle_layout); 19 togBtn = (ToggleButton) findViewById(R.id.togBtn); 20 linearLayout = (LinearLayout) this.findViewById(R.id.OriLayout); 21 22 togBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() { 23 @Override 24 public void onCheckedChanged(CompoundButton buttonView, 25 boolean isChecked) { 26 //通过判断是否选中,来设置LinearLayout的横向纵向排列 27 if (isChecked) { 28 linearLayout.setOrientation(1); 29 } else { 30 linearLayout.setOrientation(0); 31 } 32 } 33 }); 34 } 35 } 实现效果: 示例代码下载 总结 以上就讲解了一下CompoundButton抽象类下的三个实现控件类的使用,在Android-4.0之后,又新加入了一个控件Switch,对它的使用与之上介绍的三个控件类似,这里就不再详细讲解了。 本文转自承香墨影博客园博客,原文链接:http://www.cnblogs.com/plokmju/p/android_UI_CompoundButton.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Check the value configured in 'zookeeper.znode.parent'

进入hbase shell之后,执行list命令,报错如下 1 15 /04/23 15:24:31ERRORclient.HConnectionManager$HConnectionImplementation:Checkthevalueconfigured in 'zookeeper.znode.parent' .Therecouldbeamismatchwiththeoneconfigured in themaster. 查看Hbase下的logs目录,查看了其输出的日志信息Could not start ZK at requested port of 2181. ZK was started at port:2182. Aborting as clients(e.g. shell) will not be able to find this ZK quorum. 怀疑Zookeeper默认端口2181被占用, 1、使用命令lsof -i:2181查看端口被占用情况 2、杀死占用端口的进程 3、重新启动hbase,进入shell,执行list命令 本文转自巧克力黒 51CTO博客,原文链接:http://blog.51cto.com/10120275/1637616,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android:UI控件RatingBar、SeekBar、ProgressBar、RadioGroup、RadioButton、Check...

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 public class MainActivity extends Activity implements OnClickListener { @Override protected void onCreate(BundlesavedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.button1).setOnClickListener( this ); findViewById(R.id.button2).setOnClickListener( this ); findViewById(R.id.button3).setOnClickListener( this ); findViewById(R.id.button4).setOnClickListener( this ); findViewById(R.id.button5).setOnClickListener( this ); findViewById(R.id.button6).setOnClickListener( this ); } @Override public boolean onCreateOptionsMenu(Menumenu) { getMenuInflater().inflate(R.menu.activity_main,menu); return true ; } @Override public void onClick(Viewv) { switch (v.getId()) { case R.id.button1: btn1Click(); break ; case R.id.button2: btn2Click(); break ; case R.id.button3: btn3Click(); break ; case R.id.button4: btn4Click(); break ; case R.id.button5: btn5Click(); break ; case R.id.button6: btn6Click(); btn7Click(); break ; default : break ; } } private void btn7Click() //评分条 { RatingBarratingBar=(RatingBar)findViewById(R.id.ratingBar1); ratingBar.setNumStars( 5 ); ratingBar.setRating(( float ) 0.5 ); //默认显示的星星数 ratingBar.setOnRatingBarChangeListener( new OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBarratingBar, float rating, boolean fromUser) { Log.e( "RatingBar" , "onRatingChanged:" +rating); } }); } private void btn6Click() //可操作进度条 { SeekBarseekBar=(SeekBar)findViewById(R.id.seekBar1); seekBar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBarseekBar) //停止拖动 { Log.e( "SeekBar" , "onStopTrackingTouch" ); } @Override public void onStartTrackingTouch(SeekBarseekBar) //开始拖动 { Log.e( "SeekBar" , "onStartTrackingTouch" ); } @Override //进度改变 public void onProgressChanged(SeekBarseekBar, int progress, boolean fromUser) { Log.e( "SeekBar" , "onProgressChanged" ); } }); } private int progress= 0 ; private void btn5Click() //进度条 { ProgressBarprogressBar=(ProgressBar)findViewById(R.id.progressBar2); progressBar.setProgress(progress++); progressBar.setMax( 100 ); } private void btn4Click() //单选按钮 { RadioGroupradioGroup=(RadioGroup)findViewById(R.id.radioGroup1); int id=radioGroup.getCheckedRadioButtonId(); RadioButtonradioButton=(RadioButton)findViewById(id); Stringstr=radioButton.getText().toString(); TextViewtextView=(TextView)findViewById(R.id.textView1); switch (id) { case R.id.radio0: textView.setText(str); break ; case R.id.radio1: textView.setText(str); break ; case R.id.radio2: textView.setText(str); break ; default : break ; } } private void btn3Click() //设置圆形进度条消失(不占位置) { findViewById(R.id.progressBar1).setVisibility(View.GONE); } private void btn2Click() //设置圆形进度条为隐形(原位置空白) { findViewById(R.id.progressBar1).setVisibility(View.INVISIBLE); } private void btn1Click() //复选框 { CheckBoxcheckBox1=(CheckBox)findViewById(R.id.checkBox1); CheckBoxcheckBox2=(CheckBox)findViewById(R.id.checkBox2); CheckBoxcheckBox3=(CheckBox)findViewById(R.id.checkBox3); TextViewtextView=(TextView)findViewById(R.id.textView1); StringBufferstr= new StringBuffer(); if (checkBox1.isChecked()) { str.append(checkBox1.getText()); } if (checkBox2.isChecked()) { str.append(checkBox2.getText()); } if (checkBox3.isChecked()) { str.append(checkBox3.getText()); } textView.setText(str); } } 1.代码实现按钮点击方法 1 button.PerformClick() 注:只有当button.Enabled为true ==============================UI控件属性相关============================== 控件自定义: 1.圆形progressbar 系统styles里找到progressbar的style属性: 1 2 3 4 5 6 7 8 9 <stylename= "Widget.ProgressBar" > <itemname= "android:indeterminateOnly" > true </item> <itemname= "android:indeterminateDrawable" > @android :drawable/progress_medium_white</item> <itemname= "android:indeterminateBehavior" >repeat</item> <itemname= "android:indeterminateDuration" > 3500 </item> <itemname= "android:minWidth" >48dip</item> <itemname= "android:maxWidth" >48dip</item> <itemname= "android:minHeight" >48dip</item> <itemname= "android:maxHeight" >48dip</item> 其中,下面这句决定背景图案的设置,这个属性添加到控件的属性里: 1 <itemname= "android:indeterminateDrawable" >@android:drawable/progress_medium_white</item> 将系统的drawable文件夹找到progress_medium_white.xml复制到自己的项目里,并进行修改: 1 2 3 4 5 <animated-rotatexmlns:android= "http://schemas.android.com/apk/res/android" android:drawable= "@drawable/ic_launcher" android:pivotX= "50%" android:pivotY= "50%" /> 2.进度progressbar 系统style文件内容: 1 2 3 4 5 6 <stylename= "Widget.ProgressBar.Horizontal" > <itemname= "android:indeterminateOnly" > false </item> <itemname= "android:progressDrawable" > @android :drawable/progress_horizontal</item> <itemname= "android:indeterminateDrawable" > @android :drawable/progress_indeterminate_horizontal</item> <itemname= "android:minHeight" >20dip</item> <itemname= "android:maxHeight" >20dip</item> 关联的属性为: 1 name= "android:progressDrawable" 修改progress_horizontal.xml: 1 2 3 4 5 6 7 8 <layer-listxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:id= "@android:id/background" android:drawable= "@drawable/progress_bg" > </item> <itemandroid:id= "@android:id/secondaryProgress" android:drawable= "@drawable/progress_second" > </item> <itemandroid:id= "@android:id/progress" android:drawable= "@drawable/progress_color" > </item> </layer-list> 控件基本属性: (1)修改属性style 1 style= "?android:attr/progressBarStyleHorizontal" (2)最大进度值为100 1 android:max= "100" (3)初始化的进度值 1 android:secondaryProgress= "70" (4)设置为无限进度 1 android:indeterminate= "true" (5)代码设置样式 1 2 3 4 5 ProgressBarprogressBar= new ProgressBar( this ); progressBar.setIndeterminate( false ); progressBar.setProgressDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); progressBar.setIndeterminateDrawable(getResources().getDrawable(android.R.drawable.progress_indeterminate_horizontal)); progressBar.setMinimumHeight( 20 ); 3.seekbar: 类似于progressbar,只是多了个拖动按钮。 添加一个thumb属性:实际上是个selector的按钮。 4.ratingbar: 搜索ratingbar的xml文件进行修改,关联属性:progressDrawable。 以4.2版本里ratingbar_full_holo_dark的风格为例: ratingbar_full_empty_holo_dark.xml代码: 1 2 3 4 5 6 7 8 9 10 11 12 <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_off_pressed_holo_dark" /> <itemandroid:state_focused= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_off_focused_holo_dark" /> <itemandroid:state_selected= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_off_focused_holo_dark" /> <itemandroid:drawable= "@drawable/btn_rating_star_off_normal_holo_dark" /> </selector> ratingbar_full_filled_holo_dark.xml代码: 1 2 3 4 5 6 7 8 9 10 11 12 <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_pressed= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_on_pressed_holo_dark" /> <itemandroid:state_focused= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_on_focused_holo_dark" /> <itemandroid:state_selected= "true" android:state_window_focused= "true" android:drawable= "@drawable/btn_rating_star_on_focused_holo_dark" /> <itemandroid:drawable= "@drawable/btn_rating_star_on_normal_holo_dark" /> </selector> rating_style.xml代码: 1 2 3 4 5 <layer-listxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:id= "@+android:id/background" android:drawable= "@drawable/ratingbar_full_empty_holo_dark" /> <itemandroid:id= "@+android:id/secondaryProgress" android:drawable= "@drawable/ratingbar_full_empty_holo_dark" /> <itemandroid:id= "@+android:id/progress" android:drawable= "@drawable/ratingbar_full_filled_holo_dark" /> </layer-list> XML文件代码: 1 2 3 4 5 6 7 8 <RatingBar android:id= "@+id/ratingBar1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:progressDrawable= "@drawable/rating_style" android:layout_alignParentBottom= "true" android:layout_centerHorizontal= "true" android:layout_marginBottom= "35dp" /> 5.checkbox和radiobutton: checkbox可以直接添加一个属性修改为star风格: 1 android:style= "?android:attr/starStyle" 关联属性: 1 android:button= "@drawable/checkbox_selector" XML代码: 1 2 3 4 5 6 7 8 9 <CheckBox android:id= "@+id/checkBox1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentTop= "true" android:layout_centerHorizontal= "true" android:layout_marginTop= "58dp" android:button= "@drawable/checkbox_selector" android:text= "CheckBox" /> selector代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_checked= "true" android:state_pressed= "false" android:drawable= "@drawable/checkbox_cart_goods_on" ></item> <itemandroid:state_checked= "true" android:state_pressed= "true" android:drawable= "@drawable/checkbox_on" ></item> <itemandroid:state_checked= "false" android:state_pressed= "true" android:drawable= "@drawable/checkbox_off" ></item> <itemandroid:state_checked= "false" android:state_pressed= "false" android:drawable= "@drawable/checkbox_normal" ></item> </selector> 监听事件: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 mIv_CheckXieyi.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButtonbuttonView, boolean isChecked) { if (isChecked) { Log.e( "" , "updateCheckBox===false" ); } else { Log.e( "" , "updateCheckBox===true" ); } } }); 注: 左侧的图案直接使用button无法出现时,可使用drawableLeft设置,如下: 1 2 3 4 5 6 7 8 9 <RadioButton android:id= "@+id/routemenu_tab_walk" style= "@style/tab_title_maproute" android:drawableLeft= "@drawable/selector_route_walk" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_weight= "1" android:background= "@drawable/selector_tab_bg_left" android:text= "步行" /> 其中tab_title_maproute.xml代码如下: 1 2 3 4 5 6 7 8 9 10 <stylename= "tab_title_maproute" parent= "tab_title_newslist" > <itemname= "android:button" > @null </item> <itemname= "android:paddingLeft" >8dp</item> <itemname= "android:paddingRight" >8dp</item> <itemname= "android:textColor" > @color /white</item> <itemname= "android:textSize" >15sp</item> <itemname= "android:height" > @dimen /photo_gallery_tab_hight</item> <itemname= "android:background" > @drawable /selector_tab_bg_center</item> <itemname= "android:gravity" >center</item> </style> 其中selector_route_walk.xml代码如下: 1 2 3 4 5 6 7 8 9 10 <?xmlversion= "1.0" encoding= "utf-8" ?> <selectorxmlns:android= "http://schemas.android.com/apk/res/android" > <itemandroid:state_checked= "true" android:drawable= "@drawable/route_walk_nor" ></item> <itemandroid:state_pressed= "true" android:drawable= "@drawable/route_walk_nor" ></item> <itemandroid:state_selected= "true" android:drawable= "@drawable/route_walk_nor" ></item> <itemandroid:drawable= "@drawable/route_walk_pressed" ></item> </selector> 6.TextView相关: (1)DrawableTop在代码中的实现方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public ViewgetView( int position,ViewconvertView,ViewGroupparent) { LayoutInflaterinflater=getLayoutInflater(); TextViewtextView= null ; if (position== 0 ||position== 2 ||position== 8 ) { textView=(TextView)inflater.inflate( R.layout.navi_menu_item_separator, null ); } else { textView=(TextView)inflater.inflate( R.layout.navi_menu_item, null ); Drawabledrawable=getResources().getDrawable(ICONS[position]); drawable.setBounds( 0 , 0 ,drawable.getMinimumWidth(),drawable.getMinimumHeight()); textView.setCompoundDrawables(drawable, null , null , null ); //四个参数分别对应为上下左右,相当于xml里对textview设置drawabletop } textView.setText(TITLES[position]); return textView; } (2)文本添加链接功能的属性autolink: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @Override protected void onCreate(BundlesavedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.link); /* *APIdemo里:com.example.android.apis.text; */ SpannableStringss= new SpannableString( "text4:Manuallycreatedspans.Clickheretodialthephone." ); ss.setSpan( new StyleSpan(Typeface.BOLD), 0 , 30 ,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //setSpan方法可以用来根据判断文本位置设置文本特定类型 ss.setSpan( new URLSpan( "tel:4155551212" ), 31 + 6 , 31 + 10 ,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextViewt4=(TextView)findViewById(R.id.text4); t4.setText(ss); t4.setMovementMethod(LinkMovementMethod.getInstance()); } (3)为文字加阴影 1 2 3 4 5 6 7 8 9 10 11 12 <TextViewandroid:id= "@+id/tvText1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "text1" android:textSize= "28sp" android:textStyle= "bold" android:textColor= "#FFFFFF" android:shadowColor= "#ff000000" //阴影颜色 android:shadowDx= "2" //阴影的水平偏移量 android:shadowDy= "2" //阴影的垂直偏移量 android:shadowRadius= "1" //阴影的范围 /> (4)添加下划线 如果是在资源文件里,可以这样写: 1 2 3 4 5 <resources> <stringname= "hello" ><u>phone: 1390123456 </u></string> <stringname= "app_name" >MyLink</string> </resources> 如果是代码这样写. 1 2 TextViewtextView=(TextView)findViewById(R.id.testView); textView.setText(Html.fromHtml( "<u>" + "hahaha" + "</u>" )); 或者也可以这样写: 1 textview.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线 (5)通过字符串格式拼凑文本 1 2 3 4 Stringcontent=TextUtil.preventEmpty(comment.content); StringreplyToUserName=comment.replyToUser.username; StringContentBody=APP.getInstance().getString(R.string.discuss_content,replyToUserName,content); tvDiscussContent.setText(ContentBody); xml资源内写法: 1 <stringname= "discuss_content" >回复% 1 $s:% 2 $s</string> (6)设置部分字体颜色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 textView=(TextView)findViewById(R.id.textview); SpannableStringBuilderbuilder= new SpannableStringBuilder(textView.getText().toString()); //ForegroundColorSpan为文字前景色,BackgroundColorSpan为文字背景色 ForegroundColorSpanredSpan= new ForegroundColorSpan(Color.RED); ForegroundColorSpanwhiteSpan= new ForegroundColorSpan(Color.WHITE); ForegroundColorSpanblueSpan= new ForegroundColorSpan(Color.BLUE); ForegroundColorSpangreenSpan= new ForegroundColorSpan(Color.GREEN); ForegroundColorSpanyellowSpan= new ForegroundColorSpan(Color.YELLOW); builder.setSpan(redSpan, 0 , 1 ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(whiteSpan, 1 , 2 ,Spannable.SPAN_INCLUSIVE_INCLUSIVE); builder.setSpan(blueSpan, 2 , 3 ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(greenSpan, 3 , 4 ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(yellowSpan, 4 , 5 ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(builder); (7)设置style: 1 textView.setTextAppearance(mContext,R.style.labels); (8)长按复制,api>11 1 android:textIsSelectable= "true" 6.EditText相关: 1.设置默认提示: 1 2 android:hint= "请输入姓名" android:textColorHint= "#ff00ff00" android:background="@null"去掉输入框 2.取消焦点和请求焦点方法 1 2 //取消焦点 mEt_login_name.setFocusable( false ); 1 2 3 4 //请求焦点 mEt_login_name.setFocusableInTouchMode( true ); mEt_login_name.setFocusable( true ); mEt_login_name.requestFocus(); 3.监听编辑框字数 1 2 3 //字数变化 mEt_content.addTextChangedListener( this ); onTextChanged(mEt_content.getText(), 0 ,mEt_content.length(), 0 ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /** *******************监听编辑框输入字数********************************** */ @Override public void afterTextChanged(Editables) { } @Override public void beforeTextChanged(CharSequences, int start, int count, int after) { } @Override public void onTextChanged(CharSequences, int start, int before, int count) { int remain=MAX_TEXT_COUNT-mEt_content.length(); mTv_counter.setText(String.valueOf(remain)); mTv_counter.setTextColor(remain> 0 ? 0xffcfcfcf : 0xffff0000 ); } 4.监听编辑框输入回车键 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 mEt_jianhuo.setOnKeyListener( new OnKeyListener() { @Override public boolean onKey(Viewv, int keyCode,KeyEventevent) { if (KeyEvent.KEYCODE_ENTER==keyCode&&event.getAction()==KeyEvent.ACTION_DOWN) { Log.e( "mEt_jianhuo" , "enter" ); saoMaCheckedToServer(mEt_jianhuo.getText().toString()+ "" ,mData.getId()+ "" ,isUseAvg()); return true ; } return false ; } }); 5.设置软键盘回车键显示为"下一条"或者"完成"等 主要属性: imeActionLabel imeOptions singleLine 1 2 3 4 5 6 7 8 9 10 <EditText android:id= "@+id/hm_saoma_et_quxiao" android:layout_width= "wrap_content" android:layout_height= "40dp" android:layout_weight= "1" android:imeOptions= "actionNext" android:imeActionLabel= "下一条" android:singleLine= "true" android:ems= "15" /> 1 2 3 4 5 6 7 8 9 <EditText android:id= "@+id/hm_saoma_et_quxiao" android:layout_width= "wrap_content" android:layout_height= "40dp" android:layout_weight= "1" android:ems= "15" android:imeActionLabel= "完成" android:imeOptions= "actionDone" android:singleLine= "true" /> 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1200354,如需转载请自行联系原作者

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册