这是我的代码(编辑):改变字体样式动态
公共类主要活动扩展
{
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b=(Button) findViewById(R.id.button1);
txt = (TextView) findViewById(R.id.textView1);
b.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent= new Intent(Main.this,Preference.class);
startActivity(intent);
}
});
}
public void onResume()
{
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_LONG).show();
SharedPreferences myPreference=PreferenceManager.getDefaultSharedPreferences(this);
boolean first=myPreference.getBoolean("first", true);
if(first)
{
Typeface font=Typeface.MONOSPACE;
txt.setTypeface(font);
}
}
}
main.xml中,在这里有TextView的其文本样式需要更改。现在不需要重新启动应用程序生效复选框首选项的上一个问题。但问题是,当我取消选中复选框偏好它不会进入其默认状态。是吗?任何人都可以帮我在代码中弄错什么?
我已经包括它的代码。 – Tejaswini 2012-02-09 07:04:02
看到更新的响应 – 2012-02-09 07:16:05
尝试txt.requestLayout但仍然输出相同。 – Tejaswini 2012-02-09 07:37:10