我是 Android 编程的初学者。
我正在尝试更改微调器的文本大小,如某些问题 here 中提到的那样。我在 res/values/
中创建了 my_spinner_style.xml
,如下所示:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="13sp"
/>
并使用了这样的适配器:
spinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this,R.array.answers,android.R.layout.my_spinner_style);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
还尝试在布局文件夹中创建style.xml
。我的适配器无法识别 my_spinner_style
。我是否将其放置在错误的目录中?
最佳答案
应该是R.layout.my_spinner_style
,删除 android
在开始时,这使其指向 Android 包而不是您的项目。
请注意,您导入的 R 是您项目的资源,即 android.R 指向 Android 资源,而不是您的项目。
//根据屏幕尺寸编辑尺寸
dimens.xml 这是在值(默认)下:
<resources>
<!-- Font sizes in SP -->
<dimen name="small_font">14sp</dimen>
<dimen name="big_font">20sp</dimen>
</resources>
dimens.xml这是我的values-fr(法语,在你的情况下,你将有屏幕尺寸限定符)
<resources>
<!-- Font sizes in SP -->
<dimen name="small_font">16sp</dimen>
<dimen name="big_font">22sp</dimen>
</resources>
然后在我的 TextView
例如,这是我的字体大小:
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/small_font">
</TextView>
现在字体大小取决于语言(英语转到 values
,法语转到 values-fr
)您应该有相同的东西,但使用屏幕大小限定符。
关于android - 更改微调器的文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26203310/