2016-09-24 1 views
0

Я пытаюсь разработать приложение для простого прогноза погоды. Android Studio v2.2 Минимальный SDK для API10: Пряник.Поиск Функция City не отображается в Android Studio

Проблема - Мне нужен Search City вариант на мой 1-й page.So я просто редактировал menu_main.xml файл и добавил, что вариант. Моя проблема заключается в том, что параметр «Поиск города» появляется в разделе «дизайн» и «предварительный просмотр» menu_main.xml, но не появляется, когда я проверяю раздел 'design'or' preview 'моего activity_main.xml.

У меня есть тема для @ style/AppTheme в манифесте.

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

Мой файл меню это-

<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> 

Мой 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"> 

Я не добавил весь XML, поскольку это содержит только простые TextViews ,

Мои MainActivity.java это-

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

это-
<?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> 

любая помощь appreciated..thanks ..

ответ

1

Я думаю, что проблема что вы не раздуваете меню в своей деятельности. Добавить в свой MainActivity.java этот код:

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

Для создания кнопки ActionBar, проверьте: Creating a button in Android Toolbar

Смежные вопросы