0

I use the following definition for an action bar:

<style name="YesBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <!-- task bar styles go here -->
</style>

And here's my menu items definitions:

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

    <item
        android:title="@string/action_request_payment"
        android:id="@+id/actionRequestPayment"
        compat:showAsAction="never"/>

    <item
        android:title="@string/action_send_money"
        android:id="@+id/actionSendMoney"
        compat:showAsAction="never"/>

    <item
        android:title="@string/action_tx_history"
        android:icon="@drawable/ic_action_tx_history"
        android:id="@+id/actionTxHistory"
        compat:showAsAction="always"/>

    <item
        android:title="@string/action_settings"
        android:id="@+id/actionSettings"
        compat:showAsAction="never"/>

</menu>

My issue is that compat:showAsAction="always" has no effect: the icon is never shown in action bar. How can I fix this?

UPD

My activity code (I use Scala):

class WalletActivity extends ActionBarActivity {
  lazy val sack = findViewById(R.id.sack).asInstanceOf[SackView]

  override def onCreate(savedInstanceState: Bundle) {
    setContentView(R.layout.activity_wallet)
    super.onCreate(savedInstanceState)
  }

  override def onCreateOptionsMenu(menu: Menu) = {
    getMenuInflater.inflate(R.menu.ops, menu)
    true
  }
}
src091
  • 2,807
  • 7
  • 44
  • 74

2 Answers2

1

To resolve your issue you have to extends ActionBarActivity. But you have to change your style

<style name="YesBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <!-- task bar styles go here -->
</style>

With this:

<style name="YesBar" parent="Theme.AppCompat">
    <!-- task bar styles go here -->
</style>

And change the order of these methods

setContentView(R.layout.activity_wallet)
super.onCreate(savedInstanceState)

to

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_wallet)
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
  • This gives me runtime exception once I get to activity: `FATAL EXCEPTION: main java.lang.RuntimeException ... Caused by: java.lang.NullPointerException at android.support.v7.internal.app.WindowDecorActionBar.getDecorToolbar(WindowDecorActionBar.java:248)` – src091 Feb 22 '15 at 11:51
  • 1
    Do you have any method which get action bar? – Konrad Krakowiak Feb 22 '15 at 11:54
  • I don't have such methods, just a blank activity. Just posted it. – src091 Feb 22 '15 at 11:57
0

Try using android:showAsAction instead of compat:showAsAction. Or might be this Android 4.3 menu item showAsAction="always" ignored.

Community
  • 1
  • 1
Maksim
  • 264
  • 7
  • 20
  • Android Studio marks `android:showAsAction="always"` as error saying "Should use app:showAsAction with the appcompat library with xmlns:app="http://schemas.android.com/apk/res-auto" (app:showAsAction has no effect either). – src091 Feb 22 '15 at 11:37
  • Replace "app" with your app name. If doen't work, try to add this xmlns:appname instead of xmlns:compat. – Maksim Feb 22 '15 at 11:39