0

I have made a custom theme for my app which uses action bar.Now when i run my app the actionbar is visible but button in it is not visible.I dont know what went wrong.

The button is visible when i click on menu button (the 3 hardware button) but not displaying on the action bar

Style.Xml

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="TripLoggerTheme" parent="android:Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/TripLoggerActionBar</item>
        <!--<item name="android:homeAsUpIndicator">@drawable/test</item>-->


    </style>


    <!--use to style the actionbar-->

    <style name="TripLoggerActionBar" parent="android:Widget.ActionBar">

        <item name="android:background">#6e784c</item>
        <item name="android:showAsAction">ifRoom|always|collapseActionView|never|withText</item>
        <item name="android:displayOptions">homeAsUp|showHome|showTitle</item>


    </style>

Menu.Xml

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

    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:icon="@drawable/images"
        app:showAsAction="always" />
</menu>

Code

public class MainActivity extends Activity {
    private int[] images = {R.drawable.images, R.drawable.images_2, R.drawable.images_1, R.drawable.images_4, R.drawable.images, R.drawable.images_2};
    private GridView gridView;
    private LinearLayout linearLayout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_activity);

        linearLayout = (LinearLayout) findViewById(R.id.root);
        getActionBar();

//        gridView = (GridView) findViewById(R.id.grid);
//        gridView.setAdapter(new CustomAdapter(MainActivity.this, images));


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.action_settings:
                linearLayout.setVisibility(View.VISIBLE);
                break;


        }
        return true;

    }

enter image description here

As the screenshots shows,when i click on the 3 dots from below test is visible but it should be visible on the top where i have marked a cross

I tried finding out what could be the problem but all in vain.

Anuj
  • 367
  • 2
  • 6
  • 18
  • Some times you said `Button is not Visible` and some times you said `Button is visible`. What's going on? – M D Jan 21 '15 at 05:58
  • 1
    Sir the button is visible when i click on the menu button (the 3 hardware buttons home, back and menu) – Anuj Jan 21 '15 at 06:00
  • Do you mean that the action menu item is visible only when you click on the menu hardware button not not otherwise. Can you show a picture and explain? Do you mean the menu item visibility of the overflow menu icon (the tree dots ) visibility ? – Shobhit Puri Jan 21 '15 at 06:40
  • Yes exactly its only visible when i click menu hardware button and invisible otherwise – Anuj Jan 21 '15 at 06:44
  • @ShobhitPuri Sir see i have added the screenshot for better explanation – Anuj Jan 21 '15 at 07:03
  • you are using appcompat , so why not ActionBarActivity for your activity ? – MohK Jan 21 '15 at 07:24
  • Check targetSdkVersion number in your manifest or build.gradle. I've seen this when targetSdkVersion is 10 or lower (Android 2.x as target version). – Miroslav Michalec Jan 21 '15 at 07:33
  • I am not using appcompact – Anuj Jan 21 '15 at 07:43
  • @Anuj Check my answer. I think its expected. – Shobhit Puri Jan 21 '15 at 08:16

1 Answers1

0

I believe what you are experiencing is the standard Android behaviour. You may want to read the following text on the official docs on Action Overflow:

The overflow icon only appears on phones that have no menu hardware keys. Phones with menu keys display the action overflow when the user presses the key.

First, from snapshot, it seems that you are testing in emulator. Check if same happens on the device.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • Nah i am testing it on my phone – Anuj Jan 21 '15 at 08:34
  • @Anuj Cool. Even then the same stands true. This is the standard behaviour. There are various solutions online to force show the overflow icon like: http://stackoverflow.com/a/18010220/1306419 . But those are hacks. I think you should let the behaviour be consistent. If you'll try on phone which does't have hardware menu keys, then it will show. Which phone are you testing on ? You can read other answers on the link to understand better. Hope it helps. – Shobhit Puri Jan 21 '15 at 08:40