【问题标题】:Android Studio Render Title and Settings Missing缺少 Android Studio 渲染标题和设置
【发布时间】:2015-12-09 19:36:33
【问题描述】:

所以我只是在 Android 开发中迈出了第一步,但我遇到了这个我无法解决的问题。

在 Android Studio 的渲染部分,我的默认空白应用程序不显示应用程序的标题或默认设置按钮,但如果我在手机或模拟器上加载应用程序,它们会出现。这是非常奇怪和令人沮丧的。

为什么会这样?

代码:

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

<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"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

【问题讨论】:

    标签: android rendering settings title


    【解决方案1】:

    根据您的问题,请打开activity_main.xml 文件。你会在那里看到:

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

    这是您的主要活动工具栏,您在上面放了哪个屏幕截图。它有 id,但没有任何标题。您可以以编程方式更改它,但是,您不会看到直到您在模拟器或设备上运行应用程序。

    android.support.design.widget.AppBarLayout 视图来自 Google 的 Material Design。您可以从这个网站了解更多信息:

    Introduction - Material Design - Google Design Guidelines

    或参加这个免费的 Udacity 课程:

    Material Design for Android Developers

    它允许您从头开始创建自己的工具栏(如果您不喜欢现有的工具栏)。看看这段代码:

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:padding="15dp"
                android:text="That's great app!"
                android:textSize="30sp"/>
            </LinearLayout>
    
        </android.support.design.widget.AppBarLayout>
    

    这个更改后的视图也是一个具有给定名称的工具栏,但不是我在此处使用的工具栏LinearLayout 和一个TextView 项目。

    我不知道我是否回答了您的问题,但请通过添加例如 ImageView 这将是您的应用程序的徽标或设置图标,对我更改的代码进行一些试验。

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多