私たちは最終年度のプロジェクトとしてアンドロイドのチャットアプリケーションをやっています。アンドロイドの新機能です。ユーザが提供されたオプションを選択すると、フォントスタイルを動的に変更したいと思います。sharedpreferencesを使用して、 。以下は私のコードスニペットです package com.kdr.star;無効を使用して再描画が正しく機能しない
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SharedPreferences settings=PreferenceManager.getDefaultSharedPreferences(this);
boolean first=settings.getBoolean("first", false);
TextView txt = (TextView) findViewById(R.id.textView1);
if(first)
{
Typeface font=Typeface.MONOSPACE;
txt.setTypeface(font);
txt.Invalidate();
}
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent= new Intent(Main.this,Preference.class) ;
startActivity(intent);
}
});
}
}
このコードは部分的に機能しますが、部分的に機能します。チェックボックスが選択されている場合、戻ってきたときにそのインスタンスに変更が表示されません。しかし、アプリケーションを閉じて再度開くと、変更が表示されます。しかし、チェックボックスが選択されるとすぐに変更が表示されるようにしたいと思います。無効化機能もサポートしていません。それを達成するための他の方法はありますか?この点に関するいかなる指針も、かなり認められるでしょう。事前に感謝します
私のプロジェクトでは、無効化を使用していますが、描画されたものが消えないことがあります。どうして?私はそれを最後のコードint onClickListenerとして配置します。私が無効化を複製しても、私の形がはっきりしない。何が問題なのでしょうか? – deadfish
それは私にも起こりますが、invalidate()は問題ではありません。無効なループや描画されたものなど、他のコードで問題が発生している可能性があります。特に指摘されていません。 –
あなたは正しかった:) – deadfish