【发布时间】:2016-02-27 18:34:44
【问题描述】:
TLDR:我的微调器瞬间显示错误的颜色。
我的微调器有问题。每当我运行应用程序时,如果活动没有缓存在内存中,它有时会滞后。在我可以将其设置为正确的颜色之前,文本是默认颜色(如黑色)。看起来真的很不专业。
视频: 请观看此屏幕录像以查看实际情况: https://drive.google.com/file/d/0By2AG5yaBEhMRnRsbVBDU251STQ/view
代码:
public class MyActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
Spinner spinner = (Spinner) findViewById(R.id.spinner);
//Get rid of the normal toolbar's title, because the spinner is replacing the title.
getSupportActionBar().setDisplayShowTitleEnabled(false);
//Set the choices on the spinner by setting the adapter.
spinner.setAdapter(new SpinnerAdapter(toolbar.getContext(), new String[]{"Overview", "Story", "Specifications", "Poll", "Video"}, accentColor, backgroundColor));
//Set the listener for when each option is clicked.
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
//Change the selected item's text color
((TextView) view).setTextColor(backgroundColor);
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
}
});
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp">
<Spinner
android:id="@+id/spinner"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
【问题讨论】: