I have two XML layouts behaving differently, with the only difference being that one makes use of the new
<androidx.fragment.app.FragmentContainerView
and another, the older:
<fragment
In AndroidStudio, as seen in the attached photo, in the first case I don't see the layout. In the other layout, I do.
Is it an Android Studio 3.6.3 bug, or a definition matter, and how ?
printscreen of the situation how i see it in Android Studio
<fragment 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:id="#+id/fragment"
android:name="com.example.tasktimer.MainActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:layout="#layout/a_fragment_main"/>
Related
I am getting an error Class referenced in the layout file, cn.hugeterry.coordinatortablayout.CoordinatorTabLayout, was not found in the project or the libraries while importing CoordiatorTabLayout in android studio
here screenshot of the error
<?xml version="1.0" encoding="utf-8"?>
<cn.hugeterry.coordinatortablayout.CoordinatorTabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinatortablayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.prosec.Safety">
<android.support.v4.view.ViewPager
android:id="#+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</cn.hugeterry.coordinatortablayout.CoordinatorTabLayout>
You added dependency of cn.hugeterry.coordinatortablayout.CoordinatorTabLayout layout? Because this is custom Layout, not android provided Layout. You have to add the dependency to use a custom Layout. If you use the android default coordinator layout then this is not android default. The android default layout is below.
<androidx.coordinatorlayout.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">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
If your coordinatorLayout is android default then make your layout as above I added. If problem is same, let me know
I'm implementing a Navigation View on my activityHome for the first time. When i run the app and enter the home activity it function well. The problem is at the XML editor on the android studio, the Nav View is above all the other elements and doesn't let me click on them.
I haven't touch anything else but these yet.
Thanks.
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="#+id/dl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true"
tools:context=".activities.HomeActivity"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/header"
android:background="#color/colorPrimary"
app:menu="#menu/menu"
tools:ignore="MissingConstraints" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/iv_menu"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?android:selectableItemBackground"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="#+id/guideline46"
app:layout_constraintEnd_toStartOf="#+id/guideline139"
app:layout_constraintStart_toStartOf="#+id/guideline135"
app:layout_constraintTop_toTopOf="#+id/guideline45"
android:elevation="10dp"
app:srcCompat="#drawable/menubuttonofthreelines_79781" />
...
and continues with the other elements.
Your layout has nothing wrong..
The reason that Android Studio shows that the drawer layout in the Open state in the design view because you set tools:openDrawer="start" in the DrawerLayout .. if you want to see the main layout in the design mode (i.e. to make the drawer in the close state), then you need to remove this attribute.
This attribute won't affect the looking of your app when you launch it.
Documentation:
You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.
XML tools namespace is just used to show you some behavior on Android Studio, but not while you run the app. Please check documentation for more info
I am creating a single activity application using jetpack navigation. Everything is working as expected. I have a requirement to make some fragments full screen.
Here is my layout xml.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="#+id/main_drawer"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
tools:context=".features.HomeActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/main_nav_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="#navigation/main_navigation" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/main_header"
app:itemShapeInsetStart="0dp" />
</androidx.drawerlayout.widget.DrawerLayout>
As you can see I have used the android:fitsSystemWindows attribute in FragmentContainerView.
But this is not working as expected and after inspecting the layout using Layout Inspector I am seeing duplicate FragmentContainerView in the view hierarchy.
Here is a screen shot of the view hierarchy.
The problem this creates is that the first FragmentContainerView has the fitsSystemWindows attribute set to true but the second FragmentContainerView doesn't have that attribute set. I also tried the Advanced Navigation Sample and inspected the view and it also has the duplicate FragmentContainerView.
Can anyone please explain this to me? Thanks in advance.
I'm making an app and I'm using fragments in an Activity, I'm switching this fragments with the replace function. The problem here is with the WebViewFragments, when replacing an existing WebViewFragment with other some times the system navigation bar becomes white...
App screens, from left to right: Normal, error, error:
This is my layout
Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<include layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/contentPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:background="?colorAccent"
app:itemTextColor="#drawable/navigation_items_color_selector"
app:menu="#menu/menu_navigation"
style="#style/NavigationDrawerStyle"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
I'm using androids WebViewFragment so no layout there defined by me, I tried with a custom layout with the Webview as the root layout and got the same problem
The hierarchy viewer doesn't show anything abnormal
Left OK, Right Error:
On the equipment the navigation bar is showing white while on the hierarchy viewer it shows correctly, the letf image is without the problem, the right has the problem, no additional views.
I'm using gradle version 2.14.1 and the following support libs:
com.android.support:design:24.2.1
com.android.support:appcompat-v7:24.2.1
com.android.support:recyclerview-v7:24.2.1
com.android.support:cardview-v7:24.2.1
com.android.support:percent:24.2.1
Edit: forgot to mention, this happens on Android 7.0 and Android 6.0
This was caused by the webview using the layerType as LAYER_TYPE_HARDWARE, switching it to LAYER_TYPE_SOFTWARE resolved the issue
I am fairly new to android development and I am having a hard time figuring out the simplest way to create reusable code. I have found quite a few articles on google, android has a lot of parts and solutions I am having trouble seeing the pros and cons, so I will just post what I would like to do, then see what pops up.
Currently I have:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/widget_toolbar"/>
<ListView
android:background="#color/amber_A700"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar">
</ListView>
</RelativeLayout>
<apps.new.app.ui.widget.ScrimInsetsFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffffff"
android:fitsSystemWindows="true"
app:insetForeground="#4000" >
<fragment android:id="#+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.newapp.NavigationDrawerFragment"
tools:layout="#layout/frag_nav_drawer" />
</apps.new.app.ui.widget.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
Essentially what I want is to make this a library in which I could use in any project I want with a more simplistic style:
<android.my.custom.widget
...
app:drawerFragment="drawer_fragment_name"
...>
//Listview would go here
</android.my.custom.widget>
This would allow me to set the drawer fragment, include the "ScrimInsetsFrameLayout" automatically, include the toolbar automatically. Essentially I want a reusable library in which I could update and it would push to any app I use it in. What is the best practice with android dev? If this is simply a custom widget, how would I go about including other widgets in it and inserting fragments in them?
ultimately this would allow me to simplify the code a bunch and only see what is for this activity instead of seeing a bunch of boiler-plate code for the navigation drawer, RelativeLayout and toolbar.
I feel like I am just missing something obvious.
You need to create new class which inherits from DrawerLayout, inflate your views, set params.
Tutorial is here