• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Action Bar Issue

Muqali

Lurker
So I started learning programming for android 3 months ago. I realized I needed java and am pretty well versed in that now. I m getting back to the official android tutorials and I immediately stumped by getting my action bar to show. The options only show on my device if I hit the menu button. Thanks!

Main Activity:
Code:
public class MainActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.the_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

Manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.newprogram"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat" >
        <activity
            android:name="com.example.newprogram.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Menu XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="Thisisgay" >

    <!-- Search, should appear as action button -->
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        myapp:showAsAction="ifRoom"
        android:title="@string/action_search"/>
    <!-- Settings, should always be in the overflow -->
    <item
        android:id="@+id/action_settings"
        myapp:showAsAction="never"
        android:title="@string/action_settings"/>

</menu>
 
Your items shoud have attribute
android:showAsAction="always" or "ifRoom"

I have found my issue... it has something to do with:

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

I very very vaguely recall namespaces from a C++ course eons ago. I don't understand assigning a link to them. But using this solves my problem.

Thanks!
 
Back
Top Bottom