XML : Toolbar label and options menu not showing up in my app

I've had this problem for a while and it's really annoying. I'm not sure what's causing it and multiple builds as well as making new projects haven't fixed it. Here is my Java code:

  public class MainActivity extends AppCompatActivity {      Boolean toastCheck = true;      String name = "Not";      String lastName = "Available";      WebView webview;      String password = "asdf123";      SharedPreferences prefs = null;        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_main);            prefs = getSharedPreferences("com.amrapps.foodapp", MODE_PRIVATE);            name = prefs.getString("name", "");          lastName = prefs.getString("lastName", "");          password = prefs.getString("password", "");            // Check for null values and set default if empty          if(name == "") {              name = "Johnny";          }            if (lastName == "") {              lastName = "Appleseed";          }            if (password == "") {              password = "Asdf123";          }            webview = (WebView) findViewById(R.id.webview);          WebSettings webSettings = webview.getSettings();            Random random = new Random();          int emailNum = random.nextInt(50) + 1;          final String email = name.charAt(0) + lastName + emailNum + "@gmail.com";            webview.loadUrl("https://www.panerabread.com/en-us/mypanera/registration-page.html");            webSettings.setJavaScriptEnabled(true);          webview.getSettings().setDomStorageEnabled(true);            // Fill out form          webview.setWebViewClient(new WebViewClient() {              public void onPageFinished(WebView view, String url) {                  WebView myWebView = (WebView) findViewById(R.id.webview);                    //hide loading image                  //findViewById(R.id.progressBar).setVisibility(View.GONE);                  //show WebView                  findViewById(R.id.webview).setVisibility(View.VISIBLE);                    myWebView.loadUrl("javascript:document.getElementById('join_first_name').value='" + name + "';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('join_last_name').value='" + lastName + "';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('join_email').value='" + email + "';void(0);");                  myWebView.loadUrl("javascript:document.getElementById('join_confirm_email').value='" + email + "';void(0);");                  myWebView.loadUrl("javascript:document.getElementById('join_password').value='" + password + "';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('join_confirm_password').value='" + password + "';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('phone_number_a').value='231';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('phone_number_b').value='123';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('phone_number_c').value='2310';void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('join_i_agree').click();void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('join_card_not_available').click();void(0); ");                  myWebView.loadUrl("javascript:document.getElementById('#join-now-primary'); ");                    myWebView.pageDown(true);                  // Make sure a toast is only shown once.                  while (toastCheck) {                      Toast.makeText(MainActivity.this, "Click the \"join\" button.", Toast.LENGTH_SHORT).show();                      toastCheck = false;                  }              }          });          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);          fab.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View view) {                  webview.loadUrl("https://delivery1.panerabread.com/#!/orderProcess/");              }          });        }      @Override      public void onResume() {          super.onResume();            if(prefs.getBoolean("firstRun", true)) {              //Intent myIntent = new Intent(this, firstRun.class);              //startActivity(myIntent);                prefs.edit().putBoolean("firstRun", false).commit();            }      }        @Override      public boolean onCreateOptionsMenu(Menu menu)      {          MenuInflater menuInflater = getMenuInflater();          menuInflater.inflate(R.menu.menu_main, menu);          return true;      }    

activity_main.xml:

  <android.support.design.widget.CoordinatorLayout 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"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:fitsSystemWindows="true"      tools:context="com.amrapps.foodapp.MainActivity">        <android.support.design.widget.AppBarLayout          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:theme="@style/AppTheme.AppBarOverlay">            <android.support.v7.widget.Toolbar              android:id="@+id/toolbar"              android:layout_width="match_parent"              android:layout_height="?attr/actionBarSize"              android:background="?attr/colorPrimary"              app:popupTheme="@style/AppTheme.PopupOverlay" />        </android.support.design.widget.AppBarLayout>        <include layout="@layout/content_main" />        <android.support.design.widget.FloatingActionButton          android:id="@+id/fab"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_gravity="bottom|end"          android:layout_margin="@dimen/fab_margin"          android:src="@android:drawable/ic_dialog_email" />    </android.support.design.widget.CoordinatorLayout>    

content_main.xml:

  <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout 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"      android:layout_width="match_parent"      android:layout_height="match_parent"      app:layout_behavior="@string/appbar_scrolling_view_behavior"      tools:context="com.amrapps.foodapp.MainActivity"      tools:showIn="@layout/activity_main">        <WebView          android:id="@+id/webview"          android:layout_width="fill_parent"          android:layout_height="fill_parent"          android:text="Hello World!" />  </RelativeLayout>    

The only clue I have as to why this isn't working is it has something to do with the mainActivity java code. It used to work fine before I copy pasted that in there from the old malfunctioning project.

No comments:

Post a Comment