2014-03-19 82 views
0

我现在遇到了在菜单中使用“android:actionLayout”的问题。ActionBar上的自定义菜单项

我已经使用这个和一些我以前项目的工作,但现在我不知道是怎么回事。

当我输入

android:title="@string/menu_notifications" 
android:actionLayout="@layout/menu_notification" 

动作条中的每一个图标在我的应用程序更改为文本。

我尝试了很多事情没有工作过。我不知道发生了什么。

请一些建议/想法?

编辑: menu_notification.xml

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="wrap_content" 
android:layout_height="match_parent"> 
<TextView android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="TEST" 
android:textSize="20dp" 
android:textColor="#F00" 
/> 
</LinearLayout> 

编辑2:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 

    getMenuInflater().inflate(R.menu.menu_main, menu); 

    return true; 
} 
+0

确定 “menu_notification” 是一个XML –

+0

@MSS是它的XML – user1730007

+0

什么操作系统的版本,你测试过吗? –

回答

0

变化menu_notification.xml如,

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="TEST" 
    android:textSize="20dp" 
    android:textColor="#F00" 
/> 

和main.xml中,

 <item 
    android:id="@+id/log_out" 
     android:actionLayout="@layout/menu_notification" 
    android:icon="@drawable/power" 

android:showAsAction="always" 
/> 

然后,

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 

MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main, menu); 
TextView txtview=(TextView)menu.findItem(R.id.log_out).getActionView(); 
//do remaining stuff here 

}

+0

不工作,同样的纯文本“通知”出现测试此。 – user1730007

+0

是否有任何错误? –

+0

没有错误可言,但没有工作再次只显示 – user1730007