Drawer preview not showing properly in menu file - android

I'm building an app in android studio with a menu (lateral drawer), and i want to see the preview in the menu.xml file, but it shows a grey screen, it shows fine in the emulator but not in android studio
It works fine without tools:showIn="navigation_view" but i want to see the preview with navigation_view like the image below
This is what the preview looks like
It should look like this
I have tried rebuilding the app, which is the most common solution, but it still doesn't show up
This is the xml file of the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_inicio"
android:icon="#drawable/ic_message"
android:title="Inicio" />
<item
android:id="#+id/nav_animales"
android:icon="#drawable/ic_chat"
android:title="Animales" />
<item
android:id="#+id/nav_agregar"
android:icon="#drawable/ic_profile"
android:title="Agregar" />
<item
android:id="#+id/nav_editar"
android:icon="#drawable/ic_profile"
android:title="Editar" />
<item
android:id="#+id/nav_borrar"
android:icon="#drawable/ic_profile"
android:title="Borrar" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_share"
android:title="Share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_send"
android:title="Share" />
</menu>
</item>
</menu>
dependencies
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "expo.desarrollo.simbad_app"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Try doing invalidate Caches/ Restart by going to File in the Android Studio. If still no showing then, try force refresh layout from the XML design screen, can't find it? follow this link:

Please Add Design Library in Gradle Build (App Module)
after that hope it will work.
implementation 'com.android.support:design:28.0.0'

Related

AFTER adding a style resource file got Android resource linking failed

After I´ve created a style in my application which uses a gridlayout, build is not working anymore.
I´ve tried Invalidate Caches & restart, and change some gradle dependencies, but since I don´t understand what´s going on, I could not fix it.
the design was working ok without the style resource file, after I´ve created it for the buttons, the build start to fail.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0.5dp"
app:columnCount="2"
app:rowCount="4"
app:alignmentMode="alignBounds"
tools:context=".MainActivity">
<Button style="#style/MainButton"
android:id="#+id/b_1"
app:layout_column="0"
app:layout_row="0"
android:text="#string/boletim"
android:onClick="OnClick"
android:background="#drawable/ic_boletim" />
<Button
style="#style/MainButton"
android:id="#+id/b_2"
app:layout_column="1"
app:layout_row="0"
android:text="#string/salarios"
android:background="#drawable/ic_salario" />
</android.support.v7.widget.GridLayout>
this is my button resource file, which is created in the values folder
<resources>
<!-- estilo do botão -->
<style name="MainButton" >
<item name="android:layout_margin">10dp</item>
<item name="android:textColor">#141210</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24dp</item>
<item name="layout_columnWeight">1</item>
<item name="layout_rowWeight">1</item>
<item name="layout_gravity">fill_horizontal|fill_vertical</item>
</style>
</resources>
and perhaps this is usefull too, some build.gradle infos
compileSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner" minSdkVersion 23
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
buildToolsVersion = '28.0.3' }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-
beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.android.support:gridlayout-v7:27.0.0'
}
I´ve found the solution:
in the gradle app properties file the compile versionarget and build must match:
compileSdkVersion 28 and targetSdkVersion 28 and buildToolsVersion = '28.0.3'

Android Studio 3.1.3 having issues with Constraint layout

I'm trying to start a new project here but this problem is appearing. I can run the project and deploy it in an emulator but this Render problem and Using private resources is ticking me off. I've already tried all the possible solutions found in the internet but it just can't solve the problem
<?xml version="1.0" encoding="utf
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</android.support.constraint.ConstraintLayout>
Style
<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>
<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" />
Build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.acer.myapplication3"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
}
Had the same issue - went to SDK manager and installed additional SDK platforms; Oreo 8.1. It seems the issue was that the 'new' API 28 still has issues. It says partially installed, but I basically just checked the boxes for lower API's and it downloaded/installed:
Additionally, I changed my build.gradle file's SDK version, buildTools, appcompat, and design versions as below. It works now and I will move back to API 28 at a later stage when these issues have been resolved.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 27
...
dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.0.0'
}
You just need to change the following codes from the dependencies section of your build.gradle file:
From:
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
To:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
And then sync your project.
I had the same issues. For me, the reason is my project "Automatically convert third-party libraries to use AndroidXhas". Check if your problem same as mine? please simply follow the two steps described here.
to make it easy:
1st step:
Please check your gradle.properties, if you see the following lines, you might have the exact same issues as mine. You can firstly delete them.
android.useAndroidX=true
android.enableJetifier=true
2nd step: in main activity, I changed
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
into
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
Everything works all of sudden!
Try to use this:
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
}
Instead of constraint-layout:1.1.2.
This solved my issue.
Add 'Base.' before 'Theme.AppCompat.Light.DarkActionBar'
in styles.xml .
Worked for me.
On the left-hand side, click app.
Then, open the res folder.
Open up the values folder.
Click on the 'styles.xml' folder.
Change the parent variable to "Base.Theme.AppCompact.Light.DarkActionBar"
Make sure you unchecked OFF LINE option in settings > gradle, then
sync the project again while connected on network

CoordinatorLayout not working in Android Studio 3.1.3?

I know this question has been asked a lot of times but I have tried most of the solutions, and none worked for me.
This is the first time that I'm working on android studio 3.1.3, and I was following a tutorial on how to create a simple app using the basic template option from the android studio. The problem that I'm facing is;
Render Problem Failed to find style 'coordinatorLayoutStyle' in
current theme
I have tried adding this to the build.gradle file:
compile 'com.android.support:design:24.1.1'
Also this into the style.xml
<style name="AppTheme.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
styles.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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Couldn't resolve resource #style/Widget.Design.CoordinatorLayout<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
build.gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.notes"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I was having the same problem. I tried following steps from here, but still the problem persists. I think it is a common issue in android studio 3.0+, Hopefully they will fix it next update. In the Android Studio Preview 3.2 it works fine. Download Android Studio Preview and visit here to learn how to run it alongside with Android Studio stable version
Or you can try to lower your design library version to 27. (And the compile sdk version also to 27)
dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' implementation 'com.android.support:design:27.0.2' }
Try adding "Base" before Theme in styles.xml as show : - "Base.Theme.AppCompat.Light.DarkActionBar"
Permanent solution for this problem: change your build gradle (module app) to implementation com.android.support:appcompat-v7:28.0.0-alpha1.
change your build gradle (module app)
from : com.android.support:appcompat-v7:28.1.1-alpha3
to : com.android.support:appcompat-v7:27.1.1
1.try this first : make changes in Gradle (module app) for appcompat:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
2. If it doesn't work clean your project and then again build it.
In my case, it worked.

How to implement a bottom navigation bar in android?

I'm very new to Android development so i'm sure i'm making beginners mistakes here. I'm trying to implement a bottom navigation bar by following this guide here: https://segunfamisa.com/posts/bottom-navigation-view-android
I've downloaded the demo project and it works. I'm now trying to copy the code for the bottom navigation and make it work in another android studio project and am getting this error.
I think the cause of this error is this piece of xml in my main activity where it's referencing the bottom_nav_items i am trying to have show:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
design:menu="#menu/bottom_nav_items" />
I think this is to do with the folder structure I have. The demo project has a different folder structure to my project.
Where as the project I have created has this folder structure.
I think the problem is when I add folders in my project the folder doesn't appear in the package folder whereas in the demo project this is the case.
EDIT ---------------
This is my buildgradle (Project Celebreak) file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.lewisblack.celebreak"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java/com/lewisblack/celebreak/model']
res.srcDirs = ['src/main/res', 'src/main/res/menu']
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Firstly add this in layout :
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/white"
app:itemIconTint="#color/bottomdrawer"
app:itemTextColor="#color/bottomdrawer"
app:menu="#menu/bottom_navigation_main" />
then add menu like this :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_life"
android:enabled="true"
android:icon="#drawable/ic_favorite_white_24dp"
android:title="#string/bottom_main"
app:showAsAction="always" />
<item
android:id="#+id/action_contact"
android:enabled="true"
android:icon="#drawable/ic_favorite_white_24dp"
android:title="#string/bottom_contact"
app:showAsAction="always" />
<item
android:id="#+id/action_social"
android:enabled="true"
android:icon="#drawable/ic_favorite_white_24dp"
android:title="#string/bottom_social"
app:showAsAction="always" />
<item
android:id="#+id/action_application"
android:enabled="true"
android:icon="#drawable/ic_favorite_white_24dp"
android:title="#string/bottom_app"
app:showAsAction="always" />
<item
android:id="#+id/action_menu"
android:enabled="true"
android:icon="#drawable/ic_favorite_white_24dp"
android:title="#string/bottom_menu"
app:showAsAction="always" />
</menu>
Then in your Activity implement this :
BottomNavigationView bottomNavigationView;
It is not design:menu="#menu/bottom_nav_items", it should be app:menu="#menu/bottom_nav_items"
You need to create menu as Directory not as Android Resource Directory and then paste your bottom_nav_items.xml in it.
It should be:
xmlns:app="http://schemas.android.com/apk/res-auto"
app:menu="#menu/bottom_nav_items"
also make sure you had this in Gradle:
compile 'com.android.support:design:25.0.0'
For more attributes of BottomNavigationView see the Documentation
In Android Studio 2.3 they have provided this at the start of new project. Create new project and choose the bottom navigation for the start activity of your project and study their code as they provide the perfect code.
You will get other codes but, google will provide the best.
Good Luck!

No resource found that matches the given name '#android:style/theme.AppCompat

I've viewed a ton of posts regarding this issue, but everything here checks out.
Code:
Actionbar:
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
Gradle:
compileSdkVersion 'android-L'
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 8
targetSdkVersion 'android-L'
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21+'
compile 'com.android.support:support-v4:20+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.http-client:google-http-client-jackson2:1.18.0-rc'
compile 'com.google.apis:google-api-services-calendar:v3-rev75-1.17.0-rc'
compile 'com.google.api-client:google-api-client-android:1.17.0-rc'
compile 'com.google.http-client:google-http-client-gson:1.17.0-rc'
compile 'com.google.apis:google-api-services-oauth2:v2-rev63-1.17.0-rc'
compile 'com.google.android.gms:play-services:3.1.+'
compile files('libs/app-AppEngine-endpoints-android.jar')
}
Using Android Studio
YES I have support library installed
YES I have tried moving SDK versions all the way up to sdk-18
EDIT
Ctrl-Clicking on the ".../Theme.AppCompat" takes me to the correct lines in values.xml, see below:
<style name="Theme.AppCompat" parent="Theme.Base.AppCompat">
<item name="isLightTheme">false</item>
<!-- Required for use of support_simple_spinner_dropdown_item.xml -->
<item name="spinnerDropDownItemStyle"> #style/Widget.AppCompat.DropDownItem.Spinner</item>
<item name="dropdownListPreferredItemHeight">?attr/listPreferredItemHeightSmall</item>
<item name="searchResultListItemHeight">58dip</item>
Changing this to parent="#style/Theme.AppCompat" causes an error, but by defining that theme in "styles" I managed to fix it at it worked as intended.
I think it's your use of the #android prefix that's causing the problem. I struggled with it for ages until I found this answer:
https://stackoverflow.com/a/19507892/1123654

Categories

Resources