首页 > 解决方案 > XML 布局不出现

问题描述

我正在编写一个 XML 代码,但它没有出现在布局上。怎么了?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Number_Activity"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello world"/>

</LinearLayout>

标签: androidandroid-studio

解决方案


这个xml文件没有问题,因为使用了不合适的主题看不到,修改styles.xml如下:

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

在设计视图中,您可以更改主题,如图所示: 在此处输入图像描述


推荐阅读