收到以下錯誤 類型不匹配:不能從android.support.v7.app.ActionBar.LayoutParams轉換爲android.app.ActionBar.LayoutParams得到錯誤,同時增加微調器操作欄的右側
LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View spinnerView = inflater.inflate(R.layout.layout_spinner, null);
Spinner spinner = (Spinner) spinnerView.findViewById(R.id.my_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Location, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(adapter);
// spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
//
// @Override
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// // Do whatever you want with your selected item. You can get it as: parent.getItemAtPosition(position);
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> parent) {}
// });
getActionBar().setIcon(getResources().getDrawable(R.drawable.loc));//set your actionbar logo
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.RIGHT; // set your layout's gravity to 'right'
getActionBar().setCustomView(spinnerView, layoutParams); //place your layout on the actionbar
我在new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
收到錯誤,請幫助......我不能夠解決這個錯誤,因爲我是新到Android
你已經導入了錯誤的行更改'import android.app.ActionBar.LayoutParams'到'import android.support.v7.app.ActionBar.LayoutParams' – 2014-10-28 07:17:20
setCustomView(android.view.View,android.app.ActionBar .LayoutParams)類型的ActionBar不適用於參數(android.view.View,android.support.v7.app.ActionBar.LayoutParams)現在我得到這個錯誤 – anonymous 2014-10-28 07:23:39
謝謝,我知道了..可以請你告訴我如何在頁面加載時將變量ny default的值添加到微調器 – anonymous 2014-10-28 09:14:34