Button not showing android studio - android-studio

If i put the button before appbar it does not show up. If i put it inside, it shows up but it does not fit properly (height is under imageview and the two can not be in the same height). I tried different layouts other than coordinatorlayout and it hapens again there too.
<?xml version="1.0" encoding="utf-8"?>
<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"
android:alpha="1"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/search_button"
android:layout_width="55.5dp"
android:layout_height="55.5dp"
android:layout_marginLeft="298.5dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_baseline_search_24" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<ImageView
android:id="#+id/title"
android:layout_width="155dp"
android:layout_height="55.5dp"
android:minHeight="?actionBarSize"
android:src="#mipmap/ic_banner_foreground" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabGravity="center"
app:tabMode="auto" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="59dp"
android:layout_marginTop="672dp"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme.AppBarOverlay">
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="566dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="566dp" />
</androidx.viewpager.widget.ViewPager>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

It is not showing because you've used "#android:color/transparent" as background for your ImageButton. Chose another color and it will be visible. Or just add some text so that you can see it.

Related

I want to add my website menu in web-view in navigation drawer

I converted my website into an Android web-view using an empty activity. The only issue I'm having right now is displaying my website pages in the form of a menu in the navigation drawer. Please assist me in achieving this.
Here is my Layout Activity-main.xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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:id="#+id/swipeRefreshLayout"
tools:context="com.developer.arsltech.MemberPortal.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="9dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/relativeLayout">
<ImageView
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/no_internet"
android:layout_centerHorizontal="true"
android:id="#+id/noConnectionLogo"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connection"
android:layout_below="#+id/noConnectionLogo"
android:textAlignment="center"
android:textSize="26sp"
android:id="#+id/txtNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Please assist me in achieving this.

Android Material Design- Elevation shadow not working for nested inner layouts

I am writing a code with a few nested layouts. As I have used material design I also wanted to set elevation. Though elevation was working fine with the elements of outermost layout, the contents of the inner LinearLayout (nested inside a CoordinatorLayout) is not casting shadows despite setting elevation.
<?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"
android:orientation="vertical"
android:background="#color/white"
tools:context="com.joblesscoders.aditya.todolist.HomeActivity">
<TextView
android:layout_width="match_parent"
android:id="#+id/count"
android:text="Main Activity"
android:textSize="20dp"
android:elevation="5dp"
android:textColor="#color/white"
android:gravity="center_vertical"
android:background="#color/colorPrimary"
android:layout_height="50dp" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cly"
android:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sv"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lly"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<!-- More TextViews to suit purpose -->
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/ic_add2"
app:rippleColor="#color/white"
android:id="#+id/fab"
android:layout_gravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
This code in android studio designer view produces the expected result i.e.
the TextViews displaying "Task here" have required shadows, but as soon I run it on a android 6.O custom device, the page becomes:
I would be thankful if anybody corrects me or advices on the dos and don'ts. I am extremely new to android programming, and this is my first code. So please bear with me if I have made any really very silly mistake.

Coordination Layout Don't Work With Tab Layout

Good day can you help me correct this one?
In my activity_main.xml, I used Coordination Layout So that my Appbar will work.
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
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:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information">
<!--COORDINATOR LAYOUT-->
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"
/>
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:tabMode="fixed"
app:tabGravity="fill"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#ffffff"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="#layout/header"
app:menu="#menu/drawer"/>
And In my First Tab my - Organizations feeds don't work, it stuck and will not me allow to slide up to show up the feeds. But sometimes it will work sliding up but, there is an overlapping of layout. I just include my cardview_items.xml as an overview on how it looks like.
<RelativeLayout
android:orientation="vertical"
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:scrollbarAlwaysDrawVerticalTrack="true"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information">
<!--COORDINATOR LAYOUT-->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_gravity="fill_vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="1dp">
<!--Dummy Value 1-->
<include
android:id="#+id/card_item"
layout="#layout/eco_events_cardview" />
<include
android:id="#+id/card_item"
layout="#layout/eco_events_cardview" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I really need your help. I'm stuck with this one.
Thank you in advance.
It should be fairly easy to fix:
Remove ViewPager from AppBarLayout
Add ViewPager as a sibling to a AppBarLayout and add for it app:layout_behavior="#string/appbar_scrolling_view_behavior" and set layout_width & layout_height to match_parent
So your layout should look like afterwards:
<android.support.design.widget.CoordinatorLayout
....>
<android.support.design.widget.AppBarLayout
.....>
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"/>
<android.support.design.widget.TabLayout
.../>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
.....
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
I hope, it helps.

How place floatingactionbutton on end of layout

I wanna place my floatingactionbutton on the end from the bottom of a relativelayout. How i do this as best and most practical?
Here's a screenshot, how it should look:
This functionality only works when your parent layout is a coordinator layout.This can be achieved using the app:layout_anchor="" and the app:layout_anchorGravity=""
Some thing like this:
<?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/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="#id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
Hope this was helpful.
If your parent layout is Relative Layout.
Just use
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<RelativeLayout 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:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>

toolbar overlaps my fragments (multi pane)

I am trying to have two fragments shown at the same time on a horizontal orientation of my activity alongwith a toolbar. But the toolbar overlaps the fragments. I'm not sure where to place it. Btw, the toolbar comes with a navigation view, so it's in a drawerlayout.
Here's my xml.
<android.support.v4.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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
Thoughts? I need to have the fragments show up. I'm not sure I'm using the layouts correctly.
Thanks!
Hello I see your layout file. I think the problem in it. It should inside the relative layout. kindly see the below modified layout version. Apply it let me know if you have any question in it.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/main_app_toolbar"
android:orientation="horizontal">
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>

Resources