RadioGroup,RadioButton
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());
}
});
}
}
<?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>
<?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:
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的属性
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);
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);
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) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<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
</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>
<?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>