Bottom Navigation Bar in Android Studio not Working? - java

bottomNavigationView.setOnNavigationItemSelectedListener{
when (it.itemId){
R.id.local1 -> make_Fragment(fragment1)
R.id.local2-> make_Fragment(fragment2)
R.id.local3 -> make_Fragment(fragment3)
}
true
}
Here bottomNavigationView is throwing error : Unresolved reference: bottomNavigationView and also i defined the id on mainactivity.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"
tools:context=".main.MainActivity">
<FrameLayout
android:id="#+id/fl_wapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomNavigationView"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav"
/>
</RelativeLayout>
Here bottomNavigationView shows error and also when(it.itemId){
the bottomNavigationView is the id of the bottom bar.i also tried clean project and rebuild project.
tell me a solution to resolve this problem?

add these in build.gradle(:app)
id 'kotlin-android'
id 'kotlin-android-extensions'
this in dependencies
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"
like this
dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" }
add this import statement in MainActivity.kt
import kotlinx.android.synthetic.main.mainactivity.*
it will work just fine :)...

Add this dependencies in build.gradle
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
Add kotlin code implementation
Please refer this my github repository for better understanding.
https://github.com/meshramaravind/BottomNavigtaionApp

Related

NestedScrollView breaks suggestions in Android Studio

Here is the strange behavior. I have this layout:
<?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"
style="#style/AppTheme.FragmentBackground.XXXX.Parent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/appbar"
layout="#layout/layout_appbar" />
<LinearLayout
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content">
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
So far, everything seems perfect. Although, if I replace the LinearLayout with a NestedScrollView, all of a sudden, the suggestions just do not work! If I remove the nested scrollview, everything seems to work again. Here are my gradle dependencies:
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.appcompat:appcompat-resources:1.6.0'
implementation 'androidx.core:core:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.5'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.preference:preference:1.2.0'
implementation 'org.apache.commons:commons-io:1.3.2'
implementation 'androidx.fragment:fragment:1.5.5' // Forecast Charts
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' // maps v2
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.maps.android:android-maps-utils:2.4.0'
// needed for timestamps manip
implementation 'net.danlew:android.joda:2.11.2'
implementation "androidx.camera:camera-camera2:1.2.1"
implementation "androidx.camera:camera-lifecycle:1.2.1"
implementation "androidx.camera:camera-view:1.2.1"
implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0'
//implementation 'com.google.mlkit:barcode-scanning:17.0.2'
implementation 'androidx.window:window:1.0.0'
while my gradle is gradle-7.5-bin.zip and my plugins are
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
version '2.0.1' apply false }
Also a popup of broken IDE is appeared and here is the log:
java.lang.NullPointerException
at org.jetbrains.android.dom.AttributeProcessingUtil.registerAttributesForClassAndSuperclasses(AttributeProcessingUtil.java:315)
at org.jetbrains.android.dom.AttributeProcessingUtil.processLayoutAttributes(AttributeProcessingUtil.java:604)
at org.jetbrains.android.dom.AttributeProcessingUtil.processAttributes(AttributeProcessingUtil.java:681)
at org.jetbrains.android.dom.AndroidDomExtender.registerExtensions(AndroidDomExtender.java:56)
at org.jetbrains.android.dom.AndroidDomExtender.registerExtensions(AndroidDomExtender.java:28)
at com.intellij.util.xml.reflect.DomExtenderEP.extend(DomExtenderEP.java:91)
at com.intellij.util.xml.impl.DynamicGenericInfo.runDomExtenders(DynamicGenericInfo.java:124)
at com.intellij.util.xml.impl.DynamicGenericInfo.lambda$checkInitialized$0(DynamicGenericInfo.java:55)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:114)
at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:44)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
at com.intellij.util.xml.impl.DynamicGenericInfo.checkInitialized(DynamicGenericInfo.java:54)
at com.intellij.util.xml.impl.DynamicGenericInfo.getAttributeChildrenDescriptions(DynamicGenericInfo.java:231)
at com.intellij.xml.impl.dom.AbstractDomChildrenDescriptor.getAttributeDescriptor(AbstractDomChildrenDescriptor.java:184)
at com.intellij.xml.impl.dom.AbstractDomChildrenDescriptor.getAttributeDescriptor(AbstractDomChildrenDescriptor.java:195)
at org.jetbrains.android.dom.layout.LayoutElementDescriptor.getAttributeDescriptor(LayoutElementDescriptors.kt:124)
at com.intellij.psi.impl.source.xml.XmlAttributeDelegate.getDescriptionImpl(XmlAttributeDelegate.java:68)
at com.intellij.psi.impl.source.xml.XmlAttributeDelegate.lambda$getDescriptor$0(XmlAttributeDelegate.java:55)
at com.intellij.psi.util.CachedValuesManager$1.compute(CachedValuesManager.java:158)
at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:39)
at com.intellij.util.CachedValueBase.lambda$getValueWithLock$3(CachedValueBase.java:227)
at com.intellij.util.CachedValueBase.computeData(CachedValueBase.java:42)
at com.intellij.util.CachedValueBase.lambda$getValueWithLock$4(CachedValueBase.java:227)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:114)
at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:44)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:228)
at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:28)
at com.intellij.util.CachedValuesManagerImpl.getCachedValue(CachedValuesManagerImpl.java:72)
at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:155)
at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:121)
at com.intellij.psi.impl.source.xml.XmlAttributeDelegate.getDescriptor(XmlAttributeDelegate.java:53)
at com.intellij.psi.impl.source.xml.XmlAttributeImpl.getDescriptor(XmlAttributeImpl.java:191)
at com.intellij.psi.impl.source.xml.XmlAttributeReference$1.compute(XmlAttributeReference.java:23)
at com.intellij.psi.impl.source.xml.XmlAttributeReference$1.compute(XmlAttributeReference.java:20)
at com.intellij.openapi.util.NullableLazyValue.getValue(NullableLazyValue.java:20)
at com.intellij.psi.impl.source.xml.XmlAttributeReference.getDescriptor(XmlAttributeReference.java:110)
at com.intellij.psi.impl.source.xml.XmlAttributeReference.resolve(XmlAttributeReference.java:50)
at com.intellij.codeInsight.TargetElementUtilBase.getReferencedElement(TargetElementUtilBase.java:177)
at com.intellij.codeInsight.TargetElementUtilBase.doGetReferenceOrReferencedElement(TargetElementUtilBase.java:165)
at com.intellij.codeInsight.TargetElementUtilBase.getReferenceOrReferencedElement(TargetElementUtilBase.java:210)
at com.intellij.codeInsight.TargetElementUtilBase.getReferencedElement(TargetElementUtilBase.java:254)
at com.intellij.codeInsight.TargetElementUtilBase.doFindTargetElement(TargetElementUtilBase.java:233)
at com.intellij.codeInsight.TargetElementUtilBase.findTargetElement(TargetElementUtilBase.java:298)
at com.intellij.codeInsight.TargetElementUtil.findTargetElement(TargetElementUtil.java:147)
at com.jetbrains.cidr.lang.psi.impl.OCTargetElementUtil.findTargetElement(OCTargetElementUtil.java:47)
at com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider.getPsiElementIn(TextEditorPsiDataProvider.java:226)
at com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider.getSlowData(TextEditorPsiDataProvider.java:139)
at com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider.lambda$getData$0(TextEditorPsiDataProvider.java:93)
at com.intellij.ide.impl.DataManagerImpl.getSlowData(DataManagerImpl.java:153)
at com.intellij.ide.impl.DataManagerImpl.lambda$getDataRule$2(DataManagerImpl.java:121)
at com.intellij.ide.impl.DataManagerImpl.lambda$getDataRule$4(DataManagerImpl.java:126)
at com.intellij.ide.impl.DataManagerImpl.getDataFromProvider(DataManagerImpl.java:77)
at com.intellij.openapi.actionSystem.impl.PreCachedDataContext.getData(PreCachedDataContext.java:182)
at com.intellij.openapi.actionSystem.impl.PreCachedDataContext$InjectedDataContext.getData(PreCachedDataContext.java:327)
at com.intellij.openapi.actionSystem.DataKey.getData(DataKey.java:63)
at org.jetbrains.android.quickDefinitions.AndroidImplementationViewSessionFactory.createSession(AndroidImplementationViewSession.kt:55)
at com.intellij.codeInsight.hint.actions.ShowRelatedElementsActionBase.performForContext(ShowRelatedElementsActionBase.java:86)
at com.intellij.codeInsight.hint.actions.ShowRelatedElementsActionBase.actionPerformed(ShowRelatedElementsActionBase.java:63)
at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:65)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:579)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$10(IdeKeyEventDispatcher.java:704)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:95)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$11(IdeKeyEventDispatcher.java:704)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:256)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.doPerformActionInner(IdeKeyEventDispatcher.java:701)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:645)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:590)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:473)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:462)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:227)
at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:804)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:740)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
<?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"
style="#style/AppTheme.FragmentBackground.XXXX.Parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/appbar"
layout="#layout/layout_appbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
</LinearLayout>
Use Clean Project and Rebuild Project. And Sync Project with Gradle files and download the latest version of Android Studio and then it will suggest.
Sometimes, by default, Android Studio does not show the suggestion.

BottomNavigationView not working with navigation

I'm trying to make this BottomNavigationView work with navigation but is giving me head-aches.
I'll explain my setup :
this the fragment of my activity_home.xml
<fragment
android:id="#+id/nav_host_fragment"
android:layout_width="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph" />
Also I've tried with FragmentContainerView but is not working neither.
The error is on the navigation/nav_graph.xml as the error says :
Exception inflating package:navigation/nav_graph line 7
Where line 7 is :
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_graph"
app:startDestination="#id/featureHomeNavGraph">
<include //Line 7
android:id="#+id/featureHomeNavGraph"
app:graph="#navigation/feature_home_nav_graph"/>
<include
android:id="#+id/featureFavouritesNavGraph"
app:graph="#navigation/feature_favourites_nav_graph" />
....
</navigation>
Then I've created different layouts for the navigations as :
feature_home_nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:startDestination="#id/homeFragment">
<fragment
android:id="#+id/homeFragment"
android:name="package.HomeFragment"
android:label="HomeFragment" />
</navigation>
And feature_favourites_nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:startDestination="#id/favouritesFragment">
<fragment
android:id="#+id/favouritesFragment"
android:name="package.FavouritesFragment"
android:label="FavouritesFragment" />
</navigation>
Then I think the problem also comes by the implementation on my HomeActivity.kt where I have to setup the navigation stuff... I'm doing it like this :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
setSupportActionBar(findViewById(R.id.toolbar))
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment?
NavigationUI.setupWithNavController(
bottomNavigation,
navHostFragment!!.navController
)
}
Also I've tried the NavigationExtension followed on this tutorial but it did not work neither.
Note
I'm using the same id on my items of bottom_menu.xml than on the navigation graph id for the fragments.
I guess the feature_home_nav_graph doesn't have an id on the navigation tag?

R cannot be resolved to a variable (different scenario)

Firstly, I have searched and seen similar questions on Stackoverflow however I'm building outside Android studio or Eclipse so mine is a bit different and I'm looking for a solution or alternative if possible.
I am building a plugin that sends messages between Java and Javascript using Cordova.
I have 3 lines to resolve:
setContentView(R.layout.main);
mPreview = (CameraSourcePreview) findViewById(R.id.preview);
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
Specifically just the setContentView(R.layout.main), findViewById(R.id.preview) and findViewById(R.id.faceOverlay). The layout file is in ../../../res/layout/main.xml and ../../../res/layout-land/main.xml.
All I want is a way to access, I do not have a R.java file and I'm not very experienced with Java unlike Javascript.
Is there a way to point to those files please, thanks.
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/topLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<com.cordovaplugincamerapreview
android:id="#+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cordovaplugincamerapreview
android:id="#+id/faceOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.cordovaplugincamerapreview>
</LinearLayout>

Android cannot find BindingConversion in include tag

I have made a BindingConversion from boolean to visibility, however Android can't find it, but only when I use it in an include tag. It works at other elements like FrameLyout.
In my abstract ViewModel:
#BindingConversion
public static int convertBooleanToVisibility(boolean visible) {
return visible ? View.VISIBLE : View.GONE;
}
Then in my xml (TestViewModel inherits from ViewModel):
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="oliveradam.testapp.viewmodels.TestViewModel"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
app:theme="#style/toolbarStyleMusicView"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<include
android:visibility="#{viewModel.isVisible}"
layout="#layout/layout_test"
app:viewModel="#{viewModel}" />
</LinearLayout>
</layout>
Error:(139, 29) error: cannot find symbol method setVisibility(boolean)
I'm working on Android Studio 2.2 RC.
I don't know why this is not working, but I think its the layout tag in include. You can't use these tags for databinding. So I deleted the includes, used a viewstub and changed the layouts programmatically.

Custom UI library not working in project

I have added a library in my project. However, when I use any of the views provided by the library, it gives me unbound prefix error. I have added the namespace as well in my xml file, still I am getting this error.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:wingokuFlatUI="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.wingoku.flatUI.WinGokuFlatButton
android:id="#+id/wingoku3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wingoku"
android:textColor="#fff"
wingokuFlatUI:normalStateColor="#EB974E"
wingokuFlatUI:pressedStateColor="#F2784B" />
</RelativeLayout>
UPDATE:
After making some changes, now I am getting this error
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'normalStateColor' in package
'com.example.android_flatui_testing'
- error: No resource identifier found for attribute 'pressedStateColor' in package
'com.example.android_flatui_testing'
What changes can I make to the code in order to get rid of this error?
Regards
The namespace you are defining is flatUI and you are using flatui later. I think you should be using the same character casing in both the instances.
I found this website for this before...
they implemented an example for adding the xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:wingokuFlatButton="http://schemas.android.com/apk/res/com.wingoku.flatUI"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

Categories