java - missing action bar in empty activity -


i want learn how work toolbar in android , trying add menu in action bar when ran previews started project, noticed default empty activity menu bar missing! don't know why happened.

here mainactivity.xml code

<?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" tools:context="ir.cupcode.artin.contact.mainactivity"> <listview     android:id="@+id/list"     android:layout_height="match_parent"     android:layout_width="match_parent"/>  </relativelayout> 

and have block of code menu bar in mainactivity.java :

    @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.menubar, menu);     return true; } 

here menubar.xml code

 <?xml version="1.0" encoding="utf-8"?> 

<item     android:id="@+id/action_refresh"     android:orderincategory="100"     android:showasaction="always"     android:icon="@drawable/ic_action_test"     android:title="refresh"/> <item     android:id="@+id/action_settings"     android:title="settings"> </item> 

in addition error using android:showasaction="always" says should use app:showasaction appcombat library

<?xml version="1.0" encoding="utf-8"?> 

<application     android:allowbackup="true"     android:icon="@mipmap/ic_appicon2"     android:label="@string/app_name"     android:supportsrtl="true"     android:theme="@style/theme.appcompat.light.noactionbar">     <activity android:name=".mainactivity">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>         </activity>     </application> 

change app theme

  android:theme="@style/theme.appcompat.light.noactionbar" 

into

  android:theme="@style/apptheme" 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -