gpt4 book ai didi

android - ActionBarCompat 微调器不工作

转载 作者:行者123 更新时间:2023-11-30 03:16:43 43 4
gpt4 key购买 nike

我对 ActionBar 微调器有疑问。我正在使用 ActionBarCompat。我在 Gingerbread、JB 和 KK 上看到了这个问题。

这是我的 Activity :

public class WikiActivity extends ActionBarActivity implements ActionBar.OnNavigationListener {
protected ArrayList<Project> mProjects;
protected ArrayAdapter<Project> mAdapter;
public int mCurrentProjectPosition;

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initProjectsSpinner(savedInstanceState);
}

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
L.d("item" + item);
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
protected void onResume() {
super.onResume();
refreshProjectsList();
}

private void initProjectsSpinner(Bundle savedInstanceState) {
mCurrentProjectPosition = -1;
if (savedInstanceState == null) {
mProjects = new ArrayList<Project>();
mAdapter = new ProjectsSpinnerAdapter(this, R.layout.main_nav_item, mProjects);
}
}

private void enableListNavigationMode() {
L.d("current proj pos=" + mCurrentProjectPosition);
final ActionBar ab = getSupportActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ab.setListNavigationCallbacks(mAdapter, this);
if (mCurrentProjectPosition >= 0) {
ab.setSelectedNavigationItem(mCurrentProjectPosition);
}
}

public void refreshProjectsList() {
L.d("");
if (mProjects != null && mProjects.size() > 0) {
return;
}
L.d("");
Project p = new Project();
p.name = "test1";
mProjects.add(p);
p = new Project();
p.name = "test2";
mProjects.add(p);
p = new Project();
p.name = "test3";
mProjects.add(p);
p = new Project();
p.name = "test4";
mProjects.add(p);

enableListNavigationMode();
}

@Override
public boolean onNavigationItemSelected(final int itemPosition, final long itemId) {
L.d("position: " + itemPosition);
if (mProjects == null || itemPosition < 0 || itemPosition > mProjects.size()) {
return true;
}

mCurrentProjectPosition = itemPosition;
Project currentProject = mProjects.get(mCurrentProjectPosition);
L.d("currentProject=" + currentProject);

return true;
}
}

这是适配器。我同意它可以改进(例如使用 View 持有者),但这不是这里的问题。

public class ProjectsSpinnerAdapter extends ArrayAdapter<Project> {
ArrayList<Project> data;
LayoutInflater inflater;
public ProjectsSpinnerAdapter(final Context ctx, final int textViewResourceId, final ArrayList<Project> data) {
super(ctx, textViewResourceId, data);
this.data = data;
inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.main_nav_item_in_actionbar, null);
}
final TextView text = (TextView) convertView.findViewById(R.id.main_nav_ab_item_text);
if (text != null && data != null && position < data.size()) {
text.setText(data.get(position).name);
}
return convertView;
}

@Override
public View getDropDownView(final int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.main_nav_item, null);
}
final TextView text = (TextView) convertView.findViewById(R.id.main_nav_item_text);
final View image = convertView.findViewById(R.id.main_nav_item_icon);
if (text != null && image != null) {
text.setText(data.get(position).name);
image.setVisibility(View.INVISIBLE);
}
return convertView;
}

@Override
public int getCount() {
return data == null ? 0 : data.size();
}

@Override
public Project getItem(final int position) {
return null;
}

@Override
public long getItemId(final int position) {
return 0;
}
}

所以其实很简单。我的代码要复杂得多,但我可以将其简化为这样,但它仍然失败。它曾经与 ABS 完美配合,并不是我切换到 ActionBarCompat 它不再工作了。

当我触摸操作栏中的微调器时,没有任何反应。它没有展开。怎么了?

这是日志:

--- ProjectsSpinnerAdapter.java:25 ProjectsSpinnerAdapter::<init>() ---
Context: net.bicou.redmine.app.wiki.WikiActivity@431e35c0, textViewResourceId: 2130903113, data: []
--- WikiActivity.java:65 WikiActivity::refreshProjectsList() ---
--- WikiActivity.java:69 WikiActivity::refreshProjectsList() ---
--- WikiActivity.java:54 WikiActivity::enableListNavigationMode() ---
current proj pos=-1
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- WikiActivity.java:88 WikiActivity::onNavigationItemSelected() ---
position: 0
--- WikiActivity.java:95 WikiActivity::onNavigationItemSelected() ---
currentProject=Project { id: 0, name: test1, identifier: null }
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,0 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,0 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 1, convertView: android.widget.LinearLayout{42c86858 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 2, convertView: android.widget.LinearLayout{42c86858 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 3, convertView: android.widget.LinearLayout{42c86858 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......I. 0,0-0,0 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-204,144 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-204,144 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:66 ProjectsSpinnerAdapter::getCount() ---
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 0, convertView: null, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-204,144 #1020261 android:id/action_bar_spinner}
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 1, convertView: android.widget.LinearLayout{42d3a630 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-20
er}
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 2, convertView: android.widget.LinearLayout{42d3a630 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-20
er}
--- ProjectsSpinnerAdapter.java:32 ProjectsSpinnerAdapter::getView() ---
position: 3, convertView: android.widget.LinearLayout{42d3a630 V.E..... ......I. 0,0-0,0}, parent: android.widget.Spinner{43163858 VFED.... ......ID 0,0-20
er}
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0
--- ProjectsSpinnerAdapter.java:78 ProjectsSpinnerAdapter::getItemId() ---
position: 0

然后我多次点击微调器。没有什么。然后我点击操作栏中的向上按钮:

--- WikiActivity.java:26 WikiActivity::onOptionsItemSelected() ---
itemandroid.support.v7.internal.view.menu.MenuItemWrapperJB@432778d8

真的,那个微调器没有任何反应。它死了

最佳答案

发现问题。这是因为我的主题/风格。

这是应用程序主题( Activity 使用的主题):

<item name="actionDropDownStyle">@style/Theme.MyMine.DropDownNav</item>
<item name="android:actionDropDownStyle">@style/Theme.MyMine.DropDownNav</item>

这是样式声明:

<style name="Theme.MyMine.DropDownNav">
<item name="android:background">@drawable/spinner_background_ab_mymine</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_mymine</item>
<item name="android:dropDownSelector">@drawable/selectable_background_mymine</item>
</style>

这是固定的:我只需要添加一个父项。这是 HC+ 设备的修复:

<style name="Theme.MyMine.DropDownNav"
parent="android:Widget.Holo.Light.Spinner">
<item name="android:background">@drawable/spinner_background_ab_mymine</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_mymine</item>
<item name="android:dropDownSelector">@drawable/selectable_background_mymine</item>
</style>

关于android - ActionBarCompat 微调器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19962355/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com