javascript - Unable to change title and unable to show icons on action bar -


i hope doing well. first question on useful website. i'm trying create first app on android using android studio (version 2.2.2). can't seem change title or show icons have options menu. following images looks like.

the following strings.xml (some not used):

<resources> <string name="app_name">weekly duties</string> <string name="weekly">weekly things do</string> <string name="vognormal">vault of glass (normal)</string> <string name="stop">stop clicking me</string> <string name="title_search">search</string> <string name="title_share">share</string>  </resources> 

this code activity_main.xml

<?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:id="@+id/app_name" 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="hobbiapps.destinyweeklytracker.mainactivity" android:showasaction="always" >  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/weekly"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true" />  <checkbox     android:text="checkbox"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/checkbox3"     android:layout_below="@+id/checkbox1"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true" />  <checkbox     android:text="@string/vognormal"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/checkbox1"     android:layout_below="@+id/textview"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_margintop="13dp"     tools:ignore="unknownid" />   </relativelayout> 

this main_menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">   <item     android:id="@+id/settings_id"     android:title="settings"     android:orderincategory="0"     android:showasaction="always"     android:icon="@drawable/ic_settings_black_24dp" //icon settings     tools:ignore="appcompatresource" /> <item     android:id="@+id/share_id"     android:title="share"     android:showasaction="always"     android:orderincategory="0"     android:icon="@drawable/ic_share_black_24dp" //icon sharing     tools:ignore="appcompatresource" /> <item     android:id="@+id/about_me_id"     android:title="about me"     android:showasaction="never"     tools:ignore="appcompatresource" />  <item     android:id="@+id/contact_me_id"     android:title="contact me"     android:showasaction="never"     tools:ignore="appcompatresource" />  <item     android:id="@+id/search_id"     android:title="search"     android:orderincategory="0"     android:showasaction="always"     tools:ignore="appcompatresource"     android:icon="@drawable/ic_search_black_24dp"/> //icon searching   </menu> 

and last not least mainactivity.java

package hobbiapps.destinyweeklytracker;  import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.support.v7.widget.toolbar; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.support.v7.app.actionbaractivity;  public class mainactivity extends appcompatactivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); }  @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater menuinflater = getmenuinflater();     menuinflater.inflate(r.menu.main_menu, menu);     return true; } } 

thanks in advance!!!

okay, using custom toolbar? if not thats suggest doing first, adding custom toolbar. easy,

  1. create toolbar.xml layout
  2. putting follows xml

    <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar          xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/colorprimary" android:theme="@style/themeoverlay.appcompat.dark">  </android.support.v7.widget.toolbar> 

then want add these lines of code every page uses toolbar

toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);     getsupportactionbar().settitle(r.string.(your string);     getsupportactionbar().seticon(r.mipmap.(your logo); 

and in xml activity

    <include layout="@layout/toolbar"         android:id="@+id/seekrtoolbar"/> 

then in code activity

    @override public boolean oncreateoptionsmenu(menu menu) {     getmenuinflater().inflate(r.menu.main_menu, menu);     return super.oncreateoptionsmenu(menu); } 

then select items

@override public boolean onoptionsitemselected(menuitem item) {      if (item.getitemid() == r.id.settings_id) {      }     if (item.getitemid() == r.id.share_id) {      }     if (item.getitemid() == r.id.about_me_id) {      }     if (item.getitemid() == r.id.contact_me_id) {      }     if (item.getitemid() == r.id.search_id) {      }      return super.onoptionsitemselected(item); } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -