[英]Why can't I see my design in XML Android Studio?
I'm a beginner and after searching on the net for a long time I found no satisfactory and permanent solution. 我是一个初学者,经过长时间的网上搜索后,我发现没有令人满意的永久解决方案。
The problem is I can't see my design in Android Studio 3.0.1. 问题是我在Android Studio 3.0.1中看不到我的设计。
I get a screen like this: 我得到这样的屏幕:
My STYLE.XML code 我的STYLE.XML代码
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 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>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
My CONTENT CONTACT.XML code 我的CONTENT CONTACT.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="hk.ust.cse.comp107x.chatclient.Contacts"
tools:showIn="@layout/activity_contacts">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/friendListView"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
My XML code: 我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="hk.ust.cse.comp107x.chatclient.ChatClient">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="5pt"
android:id="@+id/linearLayout"
android:background="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_margin="0pt">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/messageText"
android:layout_gravity="bottom"
android:layout_weight="1"
android:hint="@string/messagehint" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sendButton"
android:src="@drawable/ic_send_black_36dp"
android:background="@android:drawable/btn_default_small" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/linearLayout"
android:padding="5pt"
android:background="@null">
<android.support.v7.widget.RecyclerView
android:id="@+id/messageList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:divider="@null"
android:scrollbars="vertical"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
</LinearLayout>
</RelativeLayout>
My BUILD.GRADLE code (app) 我的BUILD.GRADLE代码(应用程序)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "myappID"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4.1'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
}
My activity_contact.xml (maybe this is coordinator layout?) 我的activity_contact.xml (也许这是协调器布局?)
<?xml version="1.0" encoding="utf-8"?>
<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="hk.ust.cse.comp107x.chatclient.Contacts">
<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_contacts" />
<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_input_add" />
</android.support.design.widget.CoordinatorLayout>
I don't think there's a problem with Java code as I took this from a Learning course that I enrolled in Recently. 我认为Java代码没有问题,因为我是从最近参加的学习课程中学到的。
EDIT: NOW I CAN SEE MY LAYOUT BUT I HAVE A GRADLE PROJECT SYNC FAILED. 编辑:现在,我可以看到我的布局,但是我有一个失败的项目同步失败。 APPRECIATE ANY HELP
感谢任何帮助
My New Gradle code - 我的新Gradle代码-
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "hk.ust.cse.comp107x.chatclient"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4.1'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
}
Just try it, Changes on Gradle file. 只需尝试一下,更改Gradle文件即可。
compileSdkVersion 27
buildToolsVersion "27.0.0"
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
testImplementation 'junit:junit:4.12'
As I can see this post is quite old but I thought would be good if in case someone else get the same issue 正如我所看到的,这篇文章已经很老了,但我认为如果其他人遇到同样的问题,那会很好
Just go to style.xml file (which is under value) and give extension to your theme with 'Base' For exmaple: 只需转到style.xml文件(该文件处于价值之下),然后用“ Base”为您的主题扩展即可。例如:
change 更改
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.NoActionBar">
You might be getting this error 您可能会收到此错误
You need to use a Theme.AppCompat theme (or descendant) with the design library.
您需要在设计库中使用Theme.AppCompat主题(或后代)。
I found a work around for this that requires you to explicitly define a theme for Coordinator layout 我找到了解决此问题的方法,该方法要求您显式定义Coordinator布局的主题
<android.support.design.widget.CoordinatorLayout
android:theme="@style/AppTheme.NoActionBar"
...
...>
Make sure that the theme you use is child of Theme.AppCompat 确保您使用的主题是Theme.AppCompat的子主题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.