package com.example.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.lang.reflect.TypeVariable;
public class Activity_TextView_Java extends AppCompatActivity {
TextView textView1,textView2,textView3;
String text1;
Integer colorText1;
float sizeText3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_textview_java);
textView1=(TextView)findViewById(R.id.text_1);
textView2=(TextView)findViewById(R.id.text_2);
textView3=(TextView)findViewById(R.id.text_2);
text1 = textView1.getText().toString();
colorText1 = textView2.getCurrentTextColor();
sizeText3 = 24.0f;
textView1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){textView1.setText("目前焦點:TextView11111");}
else {textView1.setText(text1);}
}
});
textView2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){textView2.setTextColor(0xff0000ff);}
else {textView2.setTextColor(colorText1);}
}
});
textView3.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){textView3.setTextSize(30);}
else {textView3.setTextSize(TypedValue.COMPLEX_UNIT_SP,sizeText3);}
}
});
}
}