我的文本视图是在视图类中,我想在设置类中访问它以更改它的字体大小...我尝试了不同的方法,但我仍然没有解决方案:(请帮帮我...我的两个类的代码是......
设置类代码:
public void addItemsOnSpinner1() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
List<String> list = new ArrayList<String>();
list.add("Small");
list.add("Medium");
list.add("Large");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
}
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
apply = (Button) findViewById(R.id.apply);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
apply.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(String.valueOf(spinner1.getSelectedItem())=="Small")
{
// small1=(TextView)findViewById(R.id.textfile1);
//small1.setText("raman rayat");
// setContentView(R.layout.view);
//LayoutInflater inflater = getLayoutInflater();
//View myView = inflater.inflate(R.layout.view, null);
//TextView myTextView = (TextView)myView.findViewById(R.id.textfile1);
//view1.text1.setTextSize(50);
// myTextView.setTextSize( 5);
//setContentView(R.layout.view);
view1 obj =new view1();
obj.small();
}
else if(String.valueOf(spinner1.getSelectedItem())=="Medium")
{
// code
}
else if(String.valueOf(spinner1.getSelectedItem())=="Large")
{
// code
}
}
});
查看类代码:
public class view1 extends menu {
TextView text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
text1=(TextView)findViewById(R.id.textfile1);
Intent myintent = getIntent();
String product = myintent.getStringExtra("product");
text1.setText(product);
}
public void small() {
text1.setText("small font");
}
}
答案 0 :(得分:1)
您应该使用SharedPreferences
。这允许您将字体设置存储在Settings
类中,并从View
类加载它们。
答案 1 :(得分:0)
您需要使用构造函数将活动实例传递给类。现在你可以找到视图或者可以调用该活动类的方法