버튼을 클릭 할 때 텍스트 크기를 변경하려고합니다. XML은 : 아이스크림 샌드위치의 동적 textsize 변경
이
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello_world"
android:textSize="30sp"
android:layout_margin=""/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="72dp"
android:layout_toLeftOf="@+id/textView1"
android:text="Button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/textView1"
android:text="Button2" />
내 코드입니다 : 내가 버튼 1을 클릭
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtmain=(TextView)findViewById(R.id.textView1);
txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);
//txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);
txtmain.setTextAppearance(getApplicationContext(), 12);
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
txtmain.setBackgroundColor(Color.YELLOW);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
txtmain=(TextView)findViewById(R.id.textView1);
txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);
System.out.println("txtmain get height:"+txtmain.getHeight());
//Toast.makeText(getApplicationContext(),"txtmain get
//height:"+txtmain.getHeight() , Toast.LENGTH_LONG).show();
}
});
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
txtmain=(TextView)findViewById(R.id.textView1);
txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,80);
System.out.println("txtmain get height:"+txtmain.getHeight());
//Toast.makeText(getApplicationContext(),"txtmain get
//height:"+txtmain.getHeight() , Toast.LENGTH_LONG).show();
}
});
, 그것은 적절한 출력을 제공하지만 출력을 button1을 클릭 한 후 버튼 2를 클릭하면 변경.
레이아웃 XML을 게시 해주세요. 그것은 무슨 일이 일어나고 있는지에 대한 약간의 아이디어를 제공 할 수 있습니다. 감사! –
@NeilTownsend : xml 파일을 넣습니다. – Hemant
@AlexanderW, 제 코드를 편집하십시오. – Hemant