calk
calk

Reputation: 19

Questions regarding the setting button, action bar and the title changing

I am a noob in android development and I follow the tutoral of the android website. 1. In the part of "Starting Another Activity", I just copied the code and tried to run it, but I found after the activity is changed (changed to new page), the title of action bar will change to the name of the class of that activity. 2. When it talks about the respond of the action button, the code is written as:

public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.action_search:
            openSearch();
            return true;
        case R.id.action_settings:
            openSettings();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

However, in the default code: `public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}`  

It only return true which contains no method to respond(no openSettings()), but a "setting" word still pop out when I press it. 3. How do I remove the action bar and make it full screen?

Upvotes: 0

Views: 131

Answers (2)

makata
makata

Reputation: 2258

  1. The Name of the activity is, in your case, is declared in AndroidManifest.xml. Check the android:label attribute of your activity. You can manipulate it through java code if you want. See this SO question.
  2. Check the menu file under res/menu/your_menu_file.xml. I think it contains something like

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

The displayed icon is NOT setting icon, but overflow icon. If the overflow icon is clicked, it lists all menu items. In your case only one (i.e Setting)

  1. To hide the action bar, include these in your onCreate() method

    //getWindow().requestWindowFeature(Window.FEATURE_NO_TITLE);
    getActionBar().hide();
    

    You can also do it via xml. Look at this SO question.

Upvotes: 0

dsrees
dsrees

Reputation: 6286

Don't fully understand your question (you really didn't ask one specifically) but I think this is what you're asking

  1. How to change the title of a new activity?

    Here: How do I change the android actionbar title and icon

  2. How does settings open up?

    Android does this automatically, if the onCreateOptionsMenu(Menu menu) is called.

  3. How do i make a full screen activity?

    Here: Fullscreen Activity in Android?

In the future, be sure to look through Google and StackOverflow for you answers, most likely someone has already asked a similar question

Upvotes: 1

Related Questions