注:所有的TextView都可以加点击事件OnClickListener
用户名和密码的输入界面和聊天工具的下面布局
<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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名"
android:id="@+id/username"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入用户名"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:password="true"
android:id="@+id/edit_id"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="身份证"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入身份证号码"
android:digits="1234567890xX"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@mipmap/ic_launcher"
android:text="消息"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@mipmap/ic_launcher"
android:text="联系人"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@mipmap/ic_launcher"
android:text="动态"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@mipmap/ic_launcher"
android:text="更多"
android:gravity="center_horizontal"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码可见"
android:id="@+id/button_passwd"
android:layout_below="@+id/linearLayout"
android:layout_alignParentEnd="true" />
</RelativeLayout>
设置让密码可见
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// mTextView = (TextView)findViewById(R.id.username);
editText =(EditText) findViewById(R.id.edit_id);
btn = (Button)findViewById(R.id.button_passwd);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editText.setTransformationMethod(null);
}
});
富文本
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView)findViewById(R.id.textview);
String text = "这是一个<font color='#ff0000'>富文本</font>,加一个<img src='a_main_icon04/>'图标<img src='ic_launcher'/>啦啦";
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);
mTextView.setText(spanned);
Radio Button
xml文件
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择性别:"/>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@id/radio"
android:orientation="horizontal">
<RadioButton
android:id="@id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="其他"/>
</RadioGroup>
</LinearLayout>
java代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnCommit = (Button) findViewById(R.id.radio);
mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup);
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton rb = (RadioButton)findViewById(R.id.radio);
Log.d("sex","您的性别是:"+rb.getText());
}
});
mBtnCommit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int checkedId = mRadioGroup.getCheckedRadioButtonId();
RadioButton rb = (RadioButton)findViewById(checkedId);
Log.d("sex","您的性别是:"+rb.getText());
}
});