无法看到选定的文本android AppcompactSpinner [英] Cannot see selected text android AppcompactSpinner
本文介绍了无法看到选定的文本android AppcompactSpinner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中放置了一个应用程序压缩程序微调器.我看不到所选文本(我认为这是因为所选文本的颜色变为白色,即与背景颜色相同).我可以在下拉菜单中看到文本.
I have put an app compact spinner in my application. I am unable to see the selected text(I think this is because the colour of the selected text becomes white, i.e same as the background colour). I am able to see the text in the dropdown.
支持设计-23.3.0
minSdkVersion:15
targetSdkVersion 23
我的微调代码
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/university_spinner">
</android.support.v7.widget.AppCompatSpinner>
请参见下面的图片以了解错误
See the images below to understand the error
推荐答案
看,这是分步解决方案.
Look Here is step By step solution.
步骤:1)在您的xml文件中定义AppCompactSpinner
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/university_spinner">
</android.support.v7.widget.AppCompatSpinner>
步骤2)创建两个不同的xml文件.
xml file : spinner_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:background="#FFFFFF"
android:textColor="#000000" />
xml file : spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:ellipsize="marquee"
android:textColor="#000000"/>
步骤:3)Java代码: 声明
Step : 3 ) java code : declaration
AppCompatSpinner appCompatSpinner;
String[] skills = {"Australian National University","Monash University"};
inside OnCreate
appCompatSpinner = (AppCompatSpinner)findViewById(R.id.university_spinner);
ArrayAdapter staticAdapter = new ArrayAdapter(MainActivity.this, R.layout.spinner_item, skills);
staticAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
appCompatSpinner.setAdapter(staticAdapter);
步骤:4)不选择文本输出:
步骤:5)使用选择文本"输出:
这篇关于无法看到选定的文本android AppcompactSpinner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文