2016-09-24 1 views
0

Ich versuche, eine einfache Wettervorhersage App zu entwickeln. Android Studio v2.2 Mindestens SDK auf API10: Lebkuchen.Suche Stadt Option nicht in Android Studio

Problem - Ich brauche eine Suche Stadt Option auf meinem ersten page.So ich einfach die menu_main.xml Datei bearbeitet und diese Option hinzugefügt. Mein Problem ist, dass die Option "Stadt suchen" im Abschnitt "Design" und "Vorschau" von menu_main.xml erscheint, aber nicht erscheint, wenn ich den Abschnitt "Design" oder "Vorschau" in meiner activity_main.xml.

Ich habe Thema zu @ style/AppTheme in Manifesten auch gesetzt.

In that red highlighted part I want my menu to appear..

Mein Menü Datei ist-

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

    tools:context=".MainActivity" > 

    <item 

    android:id="@+id/change_city" 
    android:orderInCategory="100" 
    android:title="@string/change_city" 

    app:showAsAction="always"/> 

    </menu> 

Mein mainactivity.xml is-

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#ff1ba1ee"`` 
    tools:context="com.example.hp.theweatherapp.MainActivity"> 

ich nicht ganz xml hinzugefügt haben, da es nur einfache Textviews enthält .

Mein MainActivity.java ist-

package com.example.hp.theweatherapp; 

    import android.os.Bundle; 
    import android.support.v7.app.AppCompatActivity; 

    public class MainActivity extends AppCompatActivity { 

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

Manifests.xml

ist-
<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.hp.theweatherapp"> 

    <application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 

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

jede Hilfe appreciated..thanks ist ..

Antwort

1

Ich denke, dass das Problem ist, dass Sie nicht Menü in Ihrer Tätigkeit aufblasen. In Ihrem MainActivity.java diesen Code:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@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(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.change_city) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

Für ActionBar Taste erstellen, überprüfen: Creating a button in Android Toolbar

Verwandte Themen