運(yùn)行效果預(yù)覽圖:
xml布局文件源代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button
android:id="@+id/small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="大字號(hào)"/>
<Button
android:id="@+id/big"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="小字號(hào)"/>
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="你好呀,小仙女枚钓!"/>
</LinearLayout>
java文件源碼:
package com.example.wordsize;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button big = (Button)findViewById(R.id.big);
Button small = (Button)findViewById(R.id.small);
tv = (TextView)findViewById(R.id.tv);
big.setOnClickListener(this); //給按鈕設(shè)置監(jiān)聽(tīng)
small.setOnClickListener(this); //給按鈕設(shè)置監(jiān)聽(tīng)
}
public void onClick(View v){
switch (v.getId()){
case R.id.big: //當(dāng)點(diǎn)擊了大字號(hào)按鈕時(shí)
tv.setTextSize(10); //將字號(hào)設(shè)置為10
break;
case R.id.small: //當(dāng)點(diǎn)擊了小字號(hào)按鈕時(shí)
tv.setTextSize(30); //將字號(hào)設(shè)置為30
break;
default:
break;
}
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者