我使用AppCompat主题。迁移到Android Studio 1.1后,背景颜色已从透明变为灰色,更糟糕的是,旋转器显示为白色背景;由于文本颜色也是白色,因此无法读取列表中的项目。
有没有办法获得原始外观,即透明背景,或者至少在哪里必须将微调器背景颜色设置为透明?
编辑:我在屏幕上创建了一个带有2个微调器的基本测试应用程序。第一个微调器在活动布局中声明,第二个微调器来自单独的布局,并在活动布局内膨胀。 两个微调器具有相同的配置,但它们的显示方式不同。
[链接] http://s15.postimg.org/4y5nwourv/Screenshot_2015_03_12_01_23_14.png
[链接] http://s8.postimg.org/ti8x5b4w5/Screenshot_2015_03_12_01_23_26.png
我想让第一个微调器(活动布局中的微调器)显示为来自膨胀布局的微调器。
由于
已编辑:测试应用代码
Main activity
public class MainActivity extends Activity {
private Spinner spinnerLanguagesLayout, spinnerLanguagesInflated;
public List<String> languages = new ArrayList<String>();
private ArrayAdapter<String> adapterLayoutLanguages, adapterInflateLanguages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init() {
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE);
LinearLayout linearLayoutInflate = (LinearLayout) this.findViewById(R.id.linearLayoutInflate);
LinearLayout linearLayoutSpinnerLanguage = (LinearLayout) inflater.inflate(R.layout.specific_spinner_language, null, false);
linearLayoutInflate.addView(linearLayoutSpinnerLanguage);
linearLayoutSpinnerLanguage.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
languages.add("english");
languages.add("chinese");
initSpinnerLayout();
initSpinnerInflate();
}
public void initSpinnerLayout() {
spinnerLanguagesLayout = (Spinner) this.findViewById(R.id.spinnerLanguagesLayout);
adapterLayoutLanguages = new LanguagesListAdapter();
spinnerLanguagesLayout.setAdapter(adapterLayoutLanguages);
}
public void initSpinnerInflate() {
spinnerLanguagesInflated = (Spinner) this.findViewById(R.id.spinnerLanguagesInflated);
adapterInflateLanguages = new LanguagesListAdapter();
spinnerLanguagesInflated.setAdapter(adapterInflateLanguages);
}
public class LanguagesListAdapter extends ArrayAdapter<String> {
public LanguagesListAdapter() {
super (getApplicationContext(), R.layout.layout_spinner, languages);
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null)
{
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout_spinner, parent, false);
}
final TextView textViewLanguage = (TextView) view.findViewById(R.id.textView);
textViewLanguage.setText(languages.get(position));
return view;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{ // This view starts when we click the spinner.
View row = convertView;
if(row == null)
{
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.layout_spinner, parent, false);
}
final TextView textViewLanguage = (TextView) row.findViewById(R.id.textView);
textViewLanguage.setText(languages.get(position));
return row;
}
}
}
主要活动布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fluentdroid="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Spinner from activity layout"
android:id="@+id/textView2"
android:layout_gravity="center_horizontal" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/spinnerLanguagesLayout"
style="@style/Base.TextAppearance.AppCompat.Large" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutInflate"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
夸大的微调器布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Spinner from inflated layout"
android:id="@+id/textView3" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/spinnerLanguagesInflated"
style="@style/Base.TextAppearance.AppCompat.Large"/>
</LinearLayout>
微调项目布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:gravity="center_horizontal"
style="@style/Base.TextAppearance.AppCompat.Large" />
</LinearLayout>