2

When I launch the apps in Emulator, I realize the Navigation bar which shows apps name is missing. May I know what's going on?

public class MainActivity extends Activity implements OnClickListener {

EditText first_name;
EditText last_name;
Button button_submit;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    first_name = (EditText) findViewById(R.id.first_name);
    last_name = (EditText) findViewById(R.id.last_name);
    button_submit = (Button) findViewById(R.id.button_submit);
    button_submit.setOnClickListener(this);

}
@Override
public void onClick(View v) {
    Intent intent = new Intent(this, ViewActivity.class);
    intent.putExtra("first_name", first_name.getText().toString());
    intent.putExtra("last_name", last_name.getText().toString());
    startActivity(intent);
  }
}

Manifest.xml

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

<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>
    <activity android:name=".ViewActivity"></activity>
</application>

Style.xml

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

Please refer the the screenshot for reference.. Thanks!

screenshot

Marat
  • 6,142
  • 6
  • 39
  • 67
gosulove
  • 1,645
  • 2
  • 26
  • 40

5 Answers5

3

Probably you have

 android:theme="@style/AppTheme.NoActionBar" 

in your AndroidManifest.xml. If so, you need to change it to

  android:theme="@style/AppTheme"

(assuming you have AppTheme defined in styles.xml with parent parent="Theme.AppCompat.Light.DarkActionBar" or similar).

Mikhail
  • 844
  • 8
  • 18
  • android:theme="@style/AppTheme" It's default, i didn't change anything. – gosulove Jul 14 '16 at 09:29
  • Please show your `AndroidManifest.xml` and `styles.xml` then. – Mikhail Jul 14 '16 at 09:34
  • 1
    You may also try these two ideas: 1. add `ActionBar ab = getActionBar(); ab.show();` to your `onCreate()` method. 2. try making your activity extend `AppCompatActivity` instead of `Activity`. ... – Mikhail Jul 14 '16 at 10:02
2

Check this if you add toolbar in xml file like this

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

then add this code to your MainActivity.java file.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

and in Manifest.xml you have use this theme.

 android:theme="@style/AppTheme.NoActionBar"

styles.xml you have this

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
  • android:theme="@style/AppTheme" It's default theme, i didn't change anything. I just created an project and run it. How come i need to change so many things in order to show the toolbar? – gosulove Jul 14 '16 at 09:29
  • @gosulove you have to go through this pattern .. because if you have set `NoActionBar` theme then `ActionBar` is disable and you can add `Toolabr` to that place and other two thing I mention is how to show the `Toolbar`. – Harshad Pansuriya Jul 14 '16 at 09:32
  • No, i didn't set "NoActionBar " . Its default android:theme="@style/AppTheme" – gosulove Jul 14 '16 at 09:36
  • @gosulove one last thing add your `Activity` xml I will change all that thing and tell you just put the xml.. – Harshad Pansuriya Jul 14 '16 at 10:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117302/discussion-between-gosulove-and-ironman). – gosulove Jul 14 '16 at 10:20
1

If you have toolbar included in your xml, add this line of code inside of onCreate() method, right after setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Marat
  • 6,142
  • 6
  • 39
  • 67
  • It's default theme, i didn't change anything. I just created an project and run it. How come i need to change so many things in order to show the toolbar? – gosulove Jul 14 '16 at 09:30
  • Your problem seems to be more than this. But these line of code are also default and mandatory. If I delete these lines in working app, I will still be able to see my toolbar BUT it will be empty. Write these lines and see changes – Marat Jul 14 '16 at 09:33
1

There is an option in the Layout editor named 'Show layout decorations' You must have this option turned off. There is a button with the image of an eye above the mobile screen in android studio. Click on that and a drop down menu should be seen. Check the 'Show Layout Decorations' and your problem should be solved.

Shivam Singh
  • 330
  • 2
  • 10
0

It might that you have changed Style.xml file with theme style of NoActionBar

please change it to <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

and then Run

Chintak Patel
  • 748
  • 6
  • 24