第二十三天 TextView、Button

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());
            }
        });
    }
}

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章