使用 LayoutInflater setTextSize 方法不起作用:
setTextSize method doesn't work by using LayoutInflater :
我想在单击 textView 时执行 changeTextSize1 方法(在 SettingActivity.java 中)(不包含在以下代码中).
changeTextSize1 是改变 finalT textView 的 textsize 的方法。
但是没用。
SettingActivity.java
public void changeTextSize1(View v) {
TextView ts1 = (TextView) findViewById(R.id.textsize1);
TextView ts2 = (TextView) findViewById(R.id.textsize2);
TextView ts3 = (TextView) findViewById(R.id.textsize3);
ts1.setTypeface(ts1.getTypeface(), Typeface.BOLD);
ts2.setTypeface(ts2.getTypeface(), Typeface.NORMAL);
ts3.setTypeface(ts3.getTypeface(), Typeface.NORMAL);
View view = (View) getLayoutInflater().inflate(R.layout.recycler_todo, null);
TextView finalT = (TextView) view.findViewById(R.id.finalText);
finalT.setTextSize(22);
}
recycler_todo.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#56A2B7"
android:orientation="vertical">
<TextView
android:id="@+id/finalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:gravity="center"
android:text="text"
android:textSize="16sp"
android:textColor="#ffffff"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#ffffff"
android:orientation="vertical">
</LinearLayout>
下面是更多代码。
MyAdapter.java
public MyAdapter(ArrayList<TodoList> myDataset) {
mDataset = myDataset;
}
@Override
public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_todo, parent, false);
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="672dp"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#56A2B7">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
enter image description here
enter image description here
第一张图片:如果我单击“1”TextView... →
第二张图片:那句话需要更大...
需要更多代码吗?
Ohhk,所以首先你想从你的设置屏幕更改你的项目的文本大小,你想反映在你的适配器中。
然后,您只需要将该文本大小保存到 SharedPreferences,然后,在 MyAdapter onBindViewHolder方法,从设置中读取文字大小,然后设置到你的textview,就是这么简单。
这里是小问题,
public MyAdapter(ArrayList<TodoList> myDataset) {
mDataset = myDataset;
}
@Override
public MyAdapter.MyViewHolder onBindViewHolder(MyAdapter.MyViewHolder holder, int position) {
// HERE YOUR CODE GOES TO SET TEXT SIZE FROM SETTING
holder.textview.setText(readSizeFromSharedPreference())
}
我想在单击 textView 时执行 changeTextSize1 方法(在 SettingActivity.java 中)(不包含在以下代码中). changeTextSize1 是改变 finalT textView 的 textsize 的方法。 但是没用。
SettingActivity.java
public void changeTextSize1(View v) {
TextView ts1 = (TextView) findViewById(R.id.textsize1);
TextView ts2 = (TextView) findViewById(R.id.textsize2);
TextView ts3 = (TextView) findViewById(R.id.textsize3);
ts1.setTypeface(ts1.getTypeface(), Typeface.BOLD);
ts2.setTypeface(ts2.getTypeface(), Typeface.NORMAL);
ts3.setTypeface(ts3.getTypeface(), Typeface.NORMAL);
View view = (View) getLayoutInflater().inflate(R.layout.recycler_todo, null);
TextView finalT = (TextView) view.findViewById(R.id.finalText);
finalT.setTextSize(22);
}
recycler_todo.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#56A2B7"
android:orientation="vertical">
<TextView
android:id="@+id/finalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:gravity="center"
android:text="text"
android:textSize="16sp"
android:textColor="#ffffff"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#ffffff"
android:orientation="vertical">
</LinearLayout>
下面是更多代码。
MyAdapter.java
public MyAdapter(ArrayList<TodoList> myDataset) {
mDataset = myDataset;
}
@Override
public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_todo, parent, false);
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="672dp"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#56A2B7">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
enter image description here
enter image description here
第一张图片:如果我单击“1”TextView... → 第二张图片:那句话需要更大...
需要更多代码吗?
Ohhk,所以首先你想从你的设置屏幕更改你的项目的文本大小,你想反映在你的适配器中。
然后,您只需要将该文本大小保存到 SharedPreferences,然后,在 MyAdapter onBindViewHolder方法,从设置中读取文字大小,然后设置到你的textview,就是这么简单。
这里是小问题,
public MyAdapter(ArrayList<TodoList> myDataset) {
mDataset = myDataset;
}
@Override
public MyAdapter.MyViewHolder onBindViewHolder(MyAdapter.MyViewHolder holder, int position) {
// HERE YOUR CODE GOES TO SET TEXT SIZE FROM SETTING
holder.textview.setText(readSizeFromSharedPreference())
}