2012-11-15 111 views
2

有相当奇怪的问题“没有资源的发现,给定的名称匹配(在‘图标’,值为”

下面

是我的菜单activity_action_bar_main.xml,并抱怨在

android:icon="@android:drawable/ic_action_view_as_list" 

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    > 

    <item 
     android:id="@+id/menu_settings" 
     android:orderInCategory="100" 
     android:showAsAction="ifRoom|withText" 
     android:title="Action Bar1" 
     android:icon="@android:drawable/ic_action_view_as_list"/> 

</menu> 

它抱怨我的图标

[2012-11-15 02:38:53 - TabsimpleActionBar] W/ResourceType(3908): Bad XML block: header size 789 or total size 0 is larger than data size 0 
[2012-11-15 02:38:53 - TabsimpleActionBar] C:\Users\djzingo\workspace1\TabsimpleActionBar\res\menu\activity_action_bar_main.xml:4: error: Error: No resource found that matches the given name (at 'icon' with value '@android:drawable/ic_action_view_as_list'). 

但我在我的代码的其他地方使用它,它,因为它应该,所以我现在是在地方显示出来。

package com.ahmad.actionBar; 

import android.annotation.SuppressLint; 
import android.app.ActionBar; 
import android.app.ActionBar.Tab; 
import android.app.ActionBar.TabListener; 
import android.app.Activity; 
import android.app.FragmentTransaction; 
import android.os.Bundle; 
import android.view.Menu; 
import android.widget.RelativeLayout; 

@SuppressLint("NewApi") 
public class ActionBarMain extends Activity implements TabListener { 
    RelativeLayout rl; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_action_bar_main); 
     try { 
      rl = (RelativeLayout) findViewById(R.id.mainLayout); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      ActionBar bar = getActionBar(); 
      bar.addTab(bar.newTab() 
        .setText("Collection") 
        .setIcon(R.drawable.ic_action_view_as_list)//It works here 
        .setTabListener(this));;; 

      bar.addTab(bar.newTab() 
         .setText("Summary") 
         .setIcon(R.drawable.ic_action_info) 
         .setTabListener(this));;; 


      bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM 
        | ActionBar.DISPLAY_USE_LOGO); 
      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
      bar.setDisplayShowHomeEnabled(true); 
      bar.setDisplayShowTitleEnabled(false); 
      bar.show(); 

     } catch (Exception e) { 
      e.getMessage(); 
     } 

    } 

    FragMent1 fram1; 
    FragmentTransaction fragMentTra = null; 
    FragMent2 fram2; 
    FragMent3 fram3; 



    public void onTabReselected(Tab tab, FragmentTransaction ft) { 
    } 

    public void onTabSelected(Tab tab, FragmentTransaction ft) { 

     if (tab.getText().equals("Collection")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram1 = new FragMent1(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram1); 
      fragMentTra.commit(); 
     } else if (tab.getText().equals("Summary")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram2 = new FragMent2(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram2); 
      fragMentTra.commit(); 
     } else if (tab.getText().equals("Details")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram3 = new FragMent3(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram3); 
      fragMentTra.commit(); 
     } 

    } 

    public void onTabUnselected(Tab tab, FragmentTransaction ft) { 

    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_action_bar_main, menu); 
     return true; 
    } 

} 

您有什么建议,为什么它的工作原理,当我删除了android:图标=“@机器人:可绘制/ ic_action_view_as_list”行,但得到BadXML块时,我的图标添加到XML文件?

回答

3

我觉得这绘制不是机器人绘制的一部分,所以尽量

android:icon="@drawable/ic_action_view_as_list" 

代替。

相关问题