第二十三天 TextView、Button

来源:互联网 发布:Windows 10 修复模式 编辑:程序博客网 时间:2024/05/16 09:54

TextView

textViewPhone.setTextColor(Color.BLUE);//设置文本颜色textViewPhone.setAutoLinkMask(Linkify.PHONE_NUMBERS);//拨打电话(android:autoLink="phone")//上网(android:autoLink="web")textViewPhone.setText("拨打电话:18500292306");//要写在setAutoLinkMask一句的后面
 textViewPrice=(TextView)findViewById(R.id.textViewPrice); textViewPrice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);//在text上加上中划线
 textViewImg=(TextView)findViewById(R.id.textView_img);        String text="我是一个<font color='#ff0000'>富文本</font>,然后末尾加一个图标<img src='a_main_icon08'/>";        Html.ImageGetter getter=new Html.ImageGetter() {            @Override            public Drawable getDrawable(String source) {                int id=R.mipmap.ic_launcher;                Class clazz=R.mipmap.class;                try {                    Field field = clazz.getDeclaredField(source);                    id=field.getInt(clazz);                } catch (IllegalAccessException e) {                    e.printStackTrace();                }catch (NoSuchFieldException e) {                    e.printStackTrace();                }                Drawable drawable=getResources().getDrawable(id);                drawable.setBounds(0,0,drawable.getIntrinsicHeight(),drawable.getIntrinsicWidth());                return drawable;            }        };        Spanned spanned=Html.fromHtml(text,getter,null);        textViewImg.setText(spanned);

这里写图片描述

文本滚动 界面小设计

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:id="@+id/textView1"        android:layout_width="200dp"        android:layout_height="wrap_content"        android:singleLine="true"        android:ellipsize="marquee"//跑马灯        android:focusable="true"        android:focusableInTouchMode="true"        android:text="08-21 02:42:37.324  27265-27265/com.example.D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb7d26868)"        />    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:gravity="bottom">//置于底部        <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:layout_weight="1"            android:drawableTop="@mipmap/ic_launcher"            android:text="联系人"            android:gravity="center_horizontal"/>        <TextView            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:drawableTop="@mipmap/ic_launcher"            android:text="动态"            android:gravity="center_horizontal"/>    </LinearLayout></RelativeLayout>

这里写图片描述

登录小界面

android:hint=”请输入密码” (EditText中的提示语)
password=true(密码不可见)

editText_password=(EditText)findViewById(R.id.editText_password);Button button=(Button)findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {     @Override     public void onClick(View v) {     editText_password.setTransformationMethod(null);     } });//设置密码可见

这里写图片描述

Button

ninepatch:上左代表拉伸、下右代表内容

当按下按钮时,按钮变成其他颜色(使用SDK下tools中的draw9patch工具编辑图片)

drawable
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@mipmap/back" android:state_pressed="true"/>    <item android:drawable="@mipmap/picture9" /></selector>
Button
 <Button           android:layout_width="match_parent"           android:layout_height="wrap_content"           android:layout_gravity="center_horizontal"           android:text="密码可见"           android:id="@+id/button"android:background="@drawable/back_drawable"/>

RadioButton

public class MainActivity extends Activity {    private RadioGroup mRadioGroup;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.radio_layout);        mRadioGroup= (RadioGroup) findViewById(R.id.radioGroup);        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(RadioGroup group, int checkedId) {                RadioButton rb= (RadioButton) findViewById(checkedId);                Log.d("sex","您的性别是:"+rb.getText());            }        });    }}

这里写图片描述

0 0
原创粉丝点击