08-21 RadioGroup,RadioButton autoLink属性 TextView中ellipsize属性 TextView的属性
2015-08-27 18:49
495 查看
RadioGroup,RadioButton
autoLink属性
TextView中ellipsize属性
TextView的属性
//**Activity文件** public class Activitty_RadioButton extends Activity{ private RadioGroup mRadioGroup; private RadioButton mRadioButton; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_radiobutton); mRadioGroup= (RadioGroup) findViewById(R.id.radiogroup); mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { mRadioButton= (RadioButton) findViewById(checkedId); Log.d("sex","你的性别是:"+mRadioButton.getText()); } }); button= (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int checkId=mRadioGroup.getCheckedRadioButtonId(); mRadioButton= (RadioButton) findViewById(checkId); Log.d("sex","你的性别是:"+mRadioButton.getText()); } }); } } //**layout文件** <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioGroup android:id="@+id/radiogroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_vertical" android:layout_marginTop="10dp" android:checkedButton="@+id/rb_man">//设置按钮的默认值 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选择性别"/> <RadioButton android:id="@+id/rb_man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/rd_background"//改变按钮图案 android:text="男"/> <RadioButton android:id="@+id/rb_woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/rd_background" android:text="女"/> </RadioGroup> </LinearLayout> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册" /> </LinearLayout> //**改变按钮文件** //drawable.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/a_radbtn_select" android:state_checked="true"/>//改变后的必须写在前面 <item android:drawable="@mipmap/a_radbtn"/> </selector> ![这里写图片描述](http://img.blog.csdn.net/20150821193934261)
autoLink属性
<!-- android:autoLink="web"-设置自动识别链接,值web为匹配Web网址 --> <!--android:autoLink="phone"-设置自动识别链接,值phone为匹配电话号码 --> <!-- android:autoLink="email"-设置自动识别链接,值email为匹配Email地址 --> <!-- android:autoLink="all"-设置自动识别链接,值all为匹配所有 -->
TextView中ellipsize属性
android:ellipsize=”start”—–省略号显示在开头 "...pedia" android:ellipsize=”end”——省略号显示在结尾 "encyc..." android:ellipsize=”middle”—-省略号显示在中间 "en...dia" android:ellipsize=”marquee”–以横向滚动方式显示(需获得当前焦点时)
TextView的属性
//**Activity文件** public class MainActivity extends Activity { private TextView mTextViewRun; private TextView mTextViewtext; private TextView mtextviewzhong; private EditText editText; Button button; Boolean isShow=true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//连接layout文件 //演示跑马灯效果 mTextViewRun= (TextView) findViewById(R.id.textviewRun); //演示富文本,字体特殊颜色显示,添加图标 mTextViewtext= (TextView) findViewById(R.id.textview_img); String text="我是一个<font color='#ff0000'>富文本</font>,然后<img src='a_main_icon06_click'/>加一个图标"; Html.ImageGetter getter=new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { Log.d("printSource",source); int id=R.mipmap.ic_launcher; Class clazz=R.mipmap.class; try { Field field=clazz.getDeclaredField(source); id=field.getInt(clazz); Log.d("printID",""+id); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } Drawable drawable=getResources().getDrawable(id); drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight()); return drawable; } }; Spanned spanned=Html.fromHtml(text,getter,null); mTextViewtext.setText(spanned); //演示中划线 mtextviewzhong= (TextView) findViewById(R.id.textview_price); mtextviewzhong.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);//设置中划线 //TextView,Edittext 用户名、密码、注册 editText= (EditText) findViewById(R.id.edittext);//密码的输入框 button= (Button) findViewById(R.id.button);//密码可见按钮 button.setOnClickListener(new View.OnClickListener() { @Override //密码是否可见的控制 public void onClick(View v) { if(isShow){ editText.setTransformationMethod(null);//让密码不可见 }else{ editText.setTransformationMethod(new PasswordTransformationMethod());//让密码可见 } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } //**layout文件** <RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <!--跑马灯效果--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/run" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:id="@+id/textviewRun" /> <!--singleLine="true" //只在一行显示 ellipsize="marquee" //设置为跑马灯格式 focusable="true" //允许获取焦点 focusableInTouchMode="true" //通过触摸获取焦点--> <!--中划线、autoLink属性--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview_price" android:text="@string/rain" android:layout_below="@+id/textviewRun" android:autoLink="web"/> <!--演示富文本--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview_img"/> <!--EditText的属性--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_centerInParent="true"> <!--用户名--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/user_name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/input_user_name"/><!--hint属性在不输入时,显示“请输入用户名”,输入时,该字符串消失--> </LinearLayout> <!--密码--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/password" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/input_password" android:password="true" android:inputType="number" android:id="@+id/edittext"/> <!-- psaaword="true" //密码不可见 inputType="number" //设置输入类型--> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/idcard" android:drawableLeft="@mipmap/a_mall_04"/> <!-- drawableLeft //添加图标--> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/button" android:layout_gravity="center" android:background="@drawable/btn_backgroud"/> <!-- drawable //设置ninePath图片、可选择性拉伸--> </LinearLayout> <!--TextView底部并排显示--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal"> <TextView android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content" android:drawableTop="@mipmap/ic_launcher" android:text="@string/tv1" android:gravity="center"/> <TextView android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content" android:drawableTop="@mipmap/ic_launcher" android:text="@string/tv2" android:gravity="center"/> <TextView android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content" android:drawableTop="@mipmap/ic_launcher" android:text="@string/tv3" android:gravity="center"/> <TextView android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content" android:drawableTop="@mipmap/ic_launcher" android:text="@string/tv4" android:gravity="center"/> </LinearLayout> </RelativeLayout> //**按钮按下后颜色改变的文件** //drawable <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/blue_press" android:state_pressed="true"/> <!--按下后的必须写在前面 --> <item android:drawable="@mipmap/blue"/> </selector>
相关文章推荐
- 08-24 CheckBox、ImageView、ArrayAdapter、SimpleAdapter、自定义Adapter
- Android中Toast的使用
- Bus Blaster v4 design overview
- 埙曲推荐,《牧羊曲》简谱
- 大三的大学总结 自省是为了不偏离轨道
- 浅谈IOC--说清楚IOC是什么
- 08-19 Activity启动 全屏,横、竖屏 FrameLayout TableLayout Intent Extra传递数据
- HEXO+Github,搭建自己的博客,最新版HEXO配置
- Emacs 学习(二)
- 初识SVN
- CentOS学习3_CentOS6.5下安装Eclipse
- 代码规范若干建议
- iOS开发系列--地图与定位
- git使用
- VBScript random function
- BloomFilter 布隆过滤
- 08-13 登录、注册, 数据库连接
- 08-18 Activity跳转 Button LinearLayout布局 Relative属性
- JSF 2 hidden value example
- cocos2d-x Lua使用pluginx中得IOSIAP遇到的问题