【问题标题】:Android Studio Navigation bar showing Apps's name is missing?缺少显示应用程序名称的 Android Studio 导航栏?
【发布时间】:2016-07-14 09:16:12
【问题描述】:

当我在模拟器中启动应用程序时,我发现显示应用程序名称的导航栏不见了。我可以知道发生了什么事吗?

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>

请参考截图。谢谢!

【问题讨论】:

  • 你在xml和java代码上加toolbar了吗???

标签: android android-layout android-studio toolbar android-titlebar


【解决方案1】:

也许你有

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

在您的AndroidManifest.xml 中。如果是这样,您需要将其更改为

  android:theme="@style/AppTheme"

(假设您在 styles.xml 中定义了 AppTheme,父级为 parent="Theme.AppCompat.Light.DarkActionBar" 或类似的)。

【讨论】:

  • android:theme="@style/AppTheme" 是默认的,我什么都没改。
  • 然后请出示您的AndroidManifest.xmlstyles.xml
  • 你也可以试试这两个想法: 1. 将ActionBar ab = getActionBar(); ab.show(); 添加到你的onCreate() 方法中。 2. 尝试让您的活动扩展AppCompatActivity 而不是Activity。 ...
【解决方案2】:

如果您像这样在 xml 文件中添加 toolbar,请选中此项

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

然后将此代码添加到您的MainActivity.java 文件中。

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

Manifest.xml 中你已经使用了这个主题。

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

styles.xml 你有这个

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

【讨论】:

  • android:theme="@style/AppTheme" 这是默认主题,我没有更改任何内容。我刚刚创建了一个项目并运行它。为什么我需要更改这么多东西才能显示工具栏?
  • @gosulove 你必须经历这个模式..因为如果你设置了NoActionBar 主题然后ActionBar 是禁用的,你可以添加Toolabr 到那个地方和我提到的其他两件事是如何显示Toolbar
  • 不,我没有设置“NoActionBar”。它的默认 android:theme="@style/AppTheme"
  • @gosulove 最后一件事添加你的Activity xml 我会改变所有的东西并告诉你只要把xml..
【解决方案3】:

如果您的 xml 中包含 toolbar,请在 onCreate() 方法中添加这行代码,紧跟在 setContentView(R.layout.activity_main); 之后

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

【讨论】:

  • 这是默认主题,我没有更改任何内容。我刚刚创建了一个项目并运行它。为什么我需要更改这么多东西才能显示工具栏?
  • 您的问题似乎不止于此。但是这些代码行也是默认的和强制的。如果我在工作应用程序中删除这些行,我仍然可以看到我的工具栏,但它将是空的。写下这些行,看看变化
【解决方案4】:

布局编辑器中有一个名为“显示布局装饰”的选项 您必须关闭此选项。 在android studio的手机屏幕上方有一个带有眼睛图像的按钮。单击它,应该会看到一个下拉菜单。检查“显示布局装饰”,您的问题应该得到解决。

【讨论】:

    【解决方案5】:

    可能是你把Style.xml文件改成了NoActionBar的主题风格

    请改成 &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;

    然后运行

    【讨论】:

      猜你喜欢
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      相关资源
      最近更新 更多