I'm new to android development and I have this problem with my Android Studio 3.1.3 demo project or any project that I create.
Even though that I can drag and drop different controls on my design view (ConstraintLayout) but nothing shows on the design view, it shows for a split sec and then it disappears.
I can see all the elements which I drag and drop in activity_main.xml Text tab, Component Tree and even in run mode, but not in design tab, nothing shows in design view and it is always blank not even hello world shows on it.
I tried Invalidate Cache Restart, Restarting my PC, changing Zoom - In and out, Inferring constraints, but no luck. Controls
I can't do much unless I see things in design view.
Empty Design View:
Run mode view
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Button" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="181dp" />
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.libra.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.libra.myapplication"
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 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
}
Ok my problem is solved!
The following classes could not be instantiated: - android.support.v7.widget.Toolbar
I changed the res/values/styles.xml file from this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
and that solved the problem
Another workaround is to edit GradleScripts/build.gradel(Module app)
-> implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
into implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
and, if there,
-> implementation 'com.android.support:design:28.0.0-alpha3'
into implementation 'com.android.support:design:28.0.0-alpha1'
SAVE and + SyncNow
I have been having the same problem and found that this hack worked for me. I have changed the versions in app file located in the Gradle Scripts/ build.gradle(Module:app) to versions 27. CompileSdkVersion, minSdkVersion, targetSdkVersion and implementation 'com.android.support:appcompat-v7:27.0.0'. These are listed on line 4,7,8 and 23.. (it might be different for you).
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.fiv4.masterapp"
minSdkVersion 27
targetSdkVersion 27
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:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
}
For those that nothing works in this page or in the whole internet(just like me), try to uninstall your android studio then reinstall. (You don't have to uninstall sdks, avd. Settings can also stay the same. Just the main program needs uninstall)
When you reinstall Android Studio, change the version to 27 as in the image. That is it, hope it works for you too
Use stable version of support libraries.
The problem is when you are using unstable alpha support libraries. See stable libraries versions on google maven repo.
At the time of answer, most stable version of support:appcomact-v7 is 28.0.0-rc02
Replace
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' // less stable alpha
With
implementation 'com.android.support:appcompat-v7:28.0.0-rc02' // more stable
Sync, Just Restart AS. Problem resolved !
Track support:appcomact-v7 stable versions
Track support:design stable versions
Track support:recyclerview-v7 stable versions
Track support:cardview-v7 stable versions
Your layout has problem with the CheckBox widget. It has no constraint. tools:layout_editor_absoluteX and tools:layout_editor_absoluteY are only affect on design mode, but not in real running app.
Note: Don't drag/drop the widget on design view, it will generate many weird properties that not gonna work in all case, like the two properties you got. Do it in the code instead. If you want the CheckBox to be in center, do like this:
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
This will remove the error icon at the CheckBox, then a refresh may help.
Go to res/values/styles.xml file...
on line 4, its always...
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Change this with
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
No need to save the file, it will automatically be saved. Go to activity_main.xml --> Design (View) ...it should be showing it now.
Related
I'm having issues in my app after implementing the biometric library from androidx on a device with Android 7. The issues started in my main app when changing the font size in the phone's accessibility settings and the text size in the app didn't change. After pinpointing the problem, I have created a dummy app with a single "hello world" activity and I have found out that even only by declaring the library's dependency in app.gradle reproduces the bug.
This is the activity's xml:
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the build.gradle:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fontscaletestapplication"
minSdkVersion 23
targetSdkVersion 28
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 "androidx.biometric:biometric:1.0.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Worth mentioning is that if I remove the dependency for androidx biometric, the font scaling works without any problems, but as soon as I add the dependency, changing the font size has no impact on the size of the font in the app.
From what I noticed in the main app, I think it has something to do with the application context and the application resources, but I can't figure out what the problem is. I have tested on a HTC 10 with Android 7 and on emulator with API 24. Another thing worth mentioning is that the font scaling works on Android 9 and 10.
Is there something I'm missing?
Thank you.
It's caused by https://issuetracker.google.com/issues/140607881
According to the bug:
"All version before API 26 are affected, Android 8.0 is the first version where is possible to change font size globally with app compat 1.1.0"
"Fixed in latest AppCompat 1.2.0-alpha02"
I tested the latest 1.2.0-beta01 and the fix works. Here are all the versions of appcomat https://developer.android.com/jetpack/androidx/releases/appcompat.
when building the app the view i've put in appears but in the editor it is not appearing, and sometimes when i create a ImageView some of the images I pasted in the drawables causes rendering problems. I recently updated my android studio and now it is full of bugs.the image attached below is a new project, I only added image view and convert it to relative layout since constraint layout gives me a ton of errors. thank you for answering my question.
<?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:visibility="visible"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"
android:textAppearance="#style/TextAppearance.AppCompat"
android:visibility="visible" />
<ImageView
android:id="#+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp" />
</RelativeLayout>
P.S.
the image view's src or compatsrc stuff, I've deleted it since it causes errors when building just to test it out. and when opening existing projects the app folder seems to be deleted/moved.
here is the gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.rowel.animation"
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 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
SDK 28 is buggy and has lots of layout issues and program bugs.
you can try adding Base. to your theme's parent in styles.xml
eg:
<resource>
<style name="AppTheme" parent="Theme.AppCompat">
...
to
<resource>
<style name="AppTheme" parent="Base.Theme.AppCompat">
...
if doesn't work, then try Invalidating Cache
if that doesn't work either, try changing targetSdkVersion to 27 or below
Change your compileSdkVersion and targetSdkVersion to 27
and also change this
implementation 'com.android.support:appcompat-v7:27.1.1'
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
I'm trying to use Androidx. The app is pretty new, so there is not much code. I did use the "Refactor to Androidx" option in android studio. But sometime after that, it stopped working. I don't know what made it stop working.
What am I supposed to do?
But it get this error
Error inflating class androidx.constraintlayout.widget.ConstraintLayout
Main activity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
pick_image.setOnClickListener {
toast("Pick image clicked")
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/pick_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Pick image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.alvarlagerlof.blurr"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.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-jdk7:$kotlin_version"
// Androidx
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
// Testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}
EDITED 2: Since the newer version, they've reverted back to androidx.constraintlayout.widget.ConstraintLayout.
Just keep reading if you're using constraint layout version 1.1.1
EDITED: As Arturo Mejia's answer, just press ⇧⌘R or Ctrl + Shift + R to
replace any
androidx.constraintlayout.widget.ConstraintLayout
with
androidx.constraintlayout.ConstraintLayout
in all XML file that use Constraint Layout.
That's a change since constraint layout version v1.1.1 (in v1.1.0 ConstraintLayout class is still inside ".widget" package)
Old workaround answer:
Change from
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
I tried to press Command + Click at ConstraintLayout in
androidx.constraintlayout.widget.ConstraintLayout from XML file to
show the original class but it doesn't find any thing. After I edited
the constraint layout version to 1.1.0 then it's there.
In my case updating dependency
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
has helped
I fixed it by changing the gradle dependencies form alpha3 to alpha1
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!