I know this is common to ask but I really confused about how can I apply onClickListener to my navigationDrawer items, I have two items which is edit profile and Logout I just want to Toast or print if one of them is selected, Is there anyone can help me with this, I've already search on the internet , yet there's no OnClickListener I've found, need help
I think there's missing on my MainActivity which is the onCreate()
OnCreate() MainActivity
setContentView(R.layout.dashboard_main);
DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
NavigationView navigationView = (NavigationView) findViewById(R.id.navigationview);
sidemenu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior = "single">
<item android:id="#+id/editProfile"
android:icon="#drawable/history"
android:title="Edit Profile"/>
<item android:id="#+id/logout_menu"
android:icon="#drawable/logout"
android:title="Logout"/>
</group>
sidebar_header
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#color/dashboard_item_1"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp"
>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/user_logo"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFF"/>
<TextView
android:id="#+id/fullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/idNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Id no."
android:textColor="#FFFFFF"
android:textSize="12sp"/>
</LinearLayout>
dashboard_main.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:id="#+id/drawerlayout"
tools:context=".MainActivity">
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigationview"
app:headerLayout="#layout/sidebar_header"
app:menu="#menu/sidemenu"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_gravity="start"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="Toolbars"
app:titleTextColor="#FFFFFF"
app:titleMarginStart = "10dp"
android:layout_marginBottom="5dp"
tools:ignore="MissingConstraints"/>
<View
android:id="#+id/viewHeaderBackground"
android:layout_width="match_parent"
android:layout_height="#dimen/_125sdp"
android:background="#color/primary"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:text="Dashboard"
android:textColor="#color/white"
android:textSize="#dimen/_20ssp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_26sdp"
android:layout_height="#dimen/_26sdp"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:src="#drawable/user_logo"
app:layout_constraintBottom_toBottomOf="#id/textTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/textTitle"
/>
<com.google.android.material.card.MaterialCardView
android:id="#+id/cardHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_16sdp"
app:cardBackgroundColor="#color/card_background"
app:cardCornerRadius="#dimen/_16sdp"
app:layout_constraintBottom_toBottomOf="#id/viewHeaderBackground"
app:layout_constraintTop_toBottomOf="#id/viewHeaderBackground">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_14sdp">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview"
android:textColor="#color/primary_text"
android:textSize="#dimen/_14ssp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageButton
android:id="#+id/textViews"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#android:color/transparent"
android:layout_marginTop="#dimen/_8sdp"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="#+id/layoutClients"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutImpacted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_clients"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Pending"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:id="#+id/txtPending"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutImpacted"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutFollowing"
app:layout_constraintStart_toEndOf="#id/layoutClients"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_impacted"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Approved"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:id="#+id/txtApproved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutFollowing"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layoutImpacted"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_following"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Records"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:padding="#dimen/_16sdp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/dashboard_item_1"/>
<include layout="#layout/dashboard_item_2"/>
<include layout="#layout/dashboard_item_3"/>
<include layout="#layout/dashboard_item_4"/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout >
Updated I tried the code below but when I click the items it will automatically hide back the sidebar and there are no Toast pops
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem item) {
if (item.getItemId() == R.id.editProfile)
{
Toast.makeText(getApplicationContext(),"profile",Toast.LENGTH_SHORT).show();
}
else if (item.getItemId() == R.id.logout_menu)
{
Toast.makeText(getApplicationContext(),"logout",Toast.LENGTH_SHORT).show();
}
return false;
}
});
First you need to implement NavigationView.OnNavigationItemSelectedListener interface on your Activity.
then on your onCreate() method type
navigationView.setNavigationItemSelectedListener(this); after this override the method onNavigationItemSelected.
here you can use this sample code.
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
if (item.getItemId() == R.id.editProfile)
{
//edit your profile
}
else if (item.getItemId() == R.id.logout)
{
//log out
}
return false;
}
Related
I have created a bottom navigation bar in android and now I want to hide it when I scroll up and show it when I scroll down. Can someone let me know how to do it? I haven't created the navigation bar using any library. I made it with linear and Relative layouts.
Here is my XML file of the MainActivity.java
<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/MageNative_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/MageNative_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
app:theme="#style/AppTheme">
<ImageView
android:id="#+id/toolimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
/>
<TextView
android:id="#+id/tooltext"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="center_vertical"
android:text="#string/app_name"
android:textAllCaps="true"
android:textColor="#color/black"
android:textSize="15sp"
android:visibility="gone"
android:textStyle="bold"
/>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/MageNative_frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:layout_marginBottom="60dp"
android:layout_below="#+id/MageNative_toolbar">
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/bottom_toolbar"
android:background="#color/white"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:weightSum="1"
android:baselineAligned="false"
android:background="#color/white"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:id="#+id/home_icon_sect"
android:orientation="vertical"
android:layout_height="50dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:tint="#343D4E"
android:src="#drawable/home"
android:id="#+id/home_icon"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:gravity="center"
android:textSize="11sp"
android:text="#string/home"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:id="#+id/categories"
android:layout_height="50dp">
<ImageView
android:id="#+id/wish_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="#drawable/home"
android:tint="#343D4E" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:gravity="center"
android:textSize="11sp"
android:text="#string/categories"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:id="#+id/notification_icon_sect"
android:layout_height="50dp">
<ImageView
android:id="#+id/notification_icon"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="#drawable/search"
android:tint="#343D4E" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/search"
android:textColor="#color/black"
android:textSize="11sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:id="#+id/user_icon_sect"
android:layout_height="50dp">
<ImageView
android:id="#+id/user_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:src="#drawable/home"
android:tint="#343D4E" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:gravity="center"
android:textSize="11sp"
android:text="#string/account"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:id="#+id/drawer_menu_sect"
android:orientation="vertical"
android:layout_height="50dp">
<ImageView
android:id="#+id/drawer_menu"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/bag"
android:tint="#343D4E" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:gravity="center"
android:layout_below="#+id/drawer_menu"
android:textSize="11sp"
android:text="#string/cart"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<fragment
android:id="#+id/MageNative_fragment_navigation_drawer"
android:name="com.freshgrocy.app.maincontainer.FragmentDrawer"
android:layout_width="290dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:layout="#layout/fragment_drawer"
tools:layout="#layout/fragment_drawer" />
</android.support.v4.widget.DrawerLayout>
just add app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" in your BottomNavigationView.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
....
app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" />
I know maybe it's late but I got the answer , two months ago I was searching and didn't find anything but a few minutes ago I found the solution and checked it works very well on Android Kitkat beyond, and decided to share it. I extract it from AppIntro Library ,here we go :
public void setImmersiveMode(boolean isEnabled, boolean isSticky) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if(!isEnabled && isImmersiveModeEnabled) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isImmersiveModeEnabled = false;
} else if(isEnabled) {
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
if(isSticky) {
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
isImmersiveModeSticky = true;
} else {
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE;
isImmersiveModeSticky = false;
}
getWindow().getDecorView().setSystemUiVisibility(flags);
isImmersiveModeEnabled = true;
}
}
}
in your activity :
public boolean isImmersiveModeEnabled = false;
public boolean isImmersiveModeSticky = false;
and use it in your code :
setImmersiveMode(true,false);
or
setImmersiveMode(true,false);
Happy Coding :)
I have a nestedscrollview with content like some RelativeLayout, CardViews and textviews. I am using a floatingactionbutton library for some reasons, as well. So I can't use any behavior for it. I don't know how I should handle the scrollchangelistener from scrollview to hide and show the fab dynamically like a behavior.
Now, When programs or output cover full page of intent, the fab is totally disappeared. It may be behind the content. I cant access fab. I want the FloatingActionButton over the scrollview. Or show and hide the fab is also need. Please tell how to achieve that concept?
Any suggestions how to hide and show the fab while scrolling?
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none"
android:background="#fff"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<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=".programs.PrintANumber">
<android.support.v7.widget.CardView
android:id="#+id/program_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/definition_content"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Print a Number"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/sourcecode_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/program_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/program"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/sourcecode_card"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Output"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/output_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/output"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:menu_icon="#drawable/fab_add"
fab:menu_backgroundColor="#ccffffff"
app:menu_colorNormal="#color/lightGrey"
android:elevation="2dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt1"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option1"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt2"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option2"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
Try like this.
private int oldScrollYPostion = 0; // inside your class
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
if (mScrollView.getScrollY() > oldScrollYPostion) {
fab.hide();
} else if (mScrollView.getScrollY() < oldScrollYPostion || mScrollView.getScrollY() <= 0) {
fab.show();
}
oldScrollYPostion = mScrollView.getScrollY();
}
});
You are using Floating action inside the scroll view tag. take it out of scroll view.
Use something like this:
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:menu_icon="#drawable/fab_add"
fab:menu_backgroundColor="#ccffffff"
app:menu_colorNormal="#color/lightGrey"
android:elevation="2dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt1"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option1"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt2"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option2"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
</com.github.clans.fab.FloatingActionMenu>
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none"
android:background="#fff"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<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=".programs.PrintANumber">
<android.support.v7.widget.CardView
android:id="#+id/program_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/definition_content"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Print a Number"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/sourcecode_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/program_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/program"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/sourcecode_card"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Output"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/output_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/output"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
My problems :
no error in this project, i can run successful.
my button can click at a certain time.
when i click it back, it doesn't work at all.
i think my problem is near the parent.
What's my mistake in my project's parent?
Help me please.
Below is my Java file : Dashboard.java
package com.example.whatisthat;
import androidx.cardview.widget.CardView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Dashboard extends Activity implements View.OnClickListener
{
private CardView LoginBtn, CaptureBtn, AboutBtn, FeedbackBtn, IgBtn, HelpBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//DEFINE CARDS
//ADD CLICK LISTENER TO THE CARDS
LoginBtn = findViewById(R.id.Login);
LoginBtn.setOnClickListener(this);
CaptureBtn = findViewById(R.id.Capture);
CaptureBtn.setOnClickListener(this);
AboutBtn = findViewById(R.id.About);
AboutBtn.setOnClickListener(this);
FeedbackBtn = findViewById(R.id.Feedback);
FeedbackBtn.setOnClickListener(this);
IgBtn = findViewById(R.id.Ig);
IgBtn.setOnClickListener(this);
HelpBtn = findViewById(R.id.Help);
HelpBtn.setOnClickListener(this);
}
#Override
public void onClick(View view)
{
Intent i;
switch (view.getId())
{
case R.id.Login : i = new Intent(this,Login1.class);
startActivity(i);
break;
case R.id.Capture : i = new Intent(this, Capture.class);
startActivity(i);
break;
case R.id.About : i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.Feedback : i = new Intent(this, Feedback.class);
startActivity(i);
break;
case R.id.Ig : i = new Intent(this, Instagram.class);
startActivity(i);
break;
case R.id.Help : i = new Intent(this, Help.class);
startActivity(i);
break;
default:break;
}
}
}
Below is my .xml file : activity_dashboard.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=".Dashboard">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:orientation="vertical"
android:gravity="center"
android:background="#6A287E">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/iconfyp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DASHBOARD"
android:textColor="#color/colorAccent"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="215dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Login"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView1"
android:layout_height="50dp"
android:src="#drawable/people"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textSize="16sp"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonLogin"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Capture"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView2"
android:layout_height="50dp"
android:src="#drawable/cameraa"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAPTURE"
android:textSize="16sp"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonCapture"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/About"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView3"
android:layout_height="50dp"
android:src="#drawable/aboutt"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT"
android:textSize="16sp"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonAbout"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Feedback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView4"
android:layout_height="50dp"
android:src="#drawable/feedback"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEEDBACK "
android:textSize="16sp"
android:layout_below="#+id/imageView4"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonFeedback"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Ig"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView5"
android:layout_height="50dp"
android:src="#drawable/instagram"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INSTAGRAM"
android:textSize="16sp"
android:layout_below="#+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonIg"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView6"
android:layout_height="50dp"
android:src="#drawable/help"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELP"
android:textSize="16sp"
android:layout_below="#+id/imageView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonHelp"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Well You have to First Remove space from this android:foreground="?android:attr/selectableItemBackground" and add this to all the button
android:clickable="false"
If you want to Open Activity With Button Then you have to put setOnClickListener to Button .Else if you want to open Activity with Cardview you have to put setOnClickListener to cardview.
Use this for OnClick Method:
#Override
public void onClick(View view) {
if (view==LoginBtn){
startActivity(new Intent(this,Login1.class));
}else if(view==Capture){
startActivity(new Intent(this,Capture.class));
}
//Do rest by yourself.
}
I want to have an app with similar notification counter on the right side of the Imageview: here is the photo of my layout:
I want to have such Notification Counter:
Here is my activity_menu layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="datasite.com.konnex.Menu"
android:background="#ffffff">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3fc0ea">
<ImageButton
android:layout_width="120dp"
android:layout_height="38dp"
android:background="#drawable/lg1"
android:layout_marginLeft="130dp" />
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp"/>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/cases"
android:layout_marginLeft="60dp"
android:layout_marginTop="40dp"
android:id="#+id/img_cases"/>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/invoices"
android:layout_marginLeft="80dp"
android:layout_marginTop="40dp" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/announcement"
android:layout_marginLeft="60dp"
android:layout_marginTop="40dp" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/users"
android:layout_marginTop="40dp"
android:layout_marginLeft="80dp"/>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/document"
android:layout_marginTop="60dp"
android:layout_marginLeft="60dp" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/meetings"
android:layout_marginTop="60dp"
android:layout_marginLeft="80dp"/>
</GridLayout>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fffafa"
app:menu="#menu/navigation"
app:itemIconTint="#color/dark"
app:itemTextColor="#color/dark" />
</LinearLayout>
Here is my menu.java class:
public class Menu extends AppCompatActivity {
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new
BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_about:
return true;
case R.id.nav_location:
return true;
case R.id.nav_phone:
return true;
case R.id.nav_home:
return true;
}
return false;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
}
Please help to find solution to this problem. I have searched many answers but haven't found the solution specific to my case. Thanks in advance!
Wrap your every ImageView in FrameLayout like this.
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2">
<FrameLayout
android:layout_width="90dp"
android:layout_height="90dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/cases"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:background="#android:color/red"
android:layout_gravity="top|end"/>
</FrameLayout>
</GridLayout>
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fc0505"
android:text="10"
android:layout_alignParentRight="true"
android:textSize="18sp"/>
</RelativeLayout>
Wrap your images inside GridLayout with RelativeLayout and put the notificaton indicators inside RelativeLayout.
Example:
<RelativeLayout
android:layout_width="90dp"
android:layout_height="90dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/cases"
android:layout_marginLeft="60dp"
android:layout_marginTop="40dp"
android:id="#+id/img_cases"/>
<TextView
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="#FF0000"/>
</RelativeLayout>
and you can update them via
GridLayout gridLayout....
TextView item1 = (TextView) gridLayout.findViewById(R.id.item1);
item1.setText("3"); // 3 notifications
You can use a Constraint layout as follows :
<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">
<ImageView
android:id="#+id/filter"
android:layout_width="30dp"
android:layout_height="30dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/ic_baseline_filter_list_24px" />
<TextView
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circular_border"
android:gravity="center"
android:textSize="10sp"
android:textColor="#FFFFFF"
card_view:layout_constraintStart_toEndOf="#string/filter"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintTop_toTopOf="#id/filter"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Add a Drawable resource file for adding background to counter as follows :
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item xmlns:android="http://schemas.android.com/apk/res/android">
<shape android:shape="oval">
<solid android:color="#DD2C00" />
<stroke android:color="#FFFFFF" android:width="1dp" />
<size
android:height="15dp"
android:width="15dp" />
</shape>
</item>
</ripple>
This question already has answers here:
Add positive button to Dialog
(3 answers)
Closed 5 years ago.
I am new in android app development. I am making a project in android-studio.I want to show pop up dialog whatever I have declared in xml file but OK button is not showing. If anyone knows about it, please share your answer.xml and java codes are below
image_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--<ImageView android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" android:src="YOUR IMAGE"/>-->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardViewbluetooth"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingTop="180dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth not enabled"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please enable bluetooth in settings and restart this application"
android:textStyle="bold"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="OK" android:onClick="dismissListener"/>
</LinearLayout>
</android.support.v7.widget.CardView></LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="litifer.awesome.game.litifer_carddemo.MainActivity"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageBeacon"
android:src="#drawable/beacon"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1text"
android:text="Beacon Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageWifi"
android:src="#drawable/wifi"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2text"
android:text="Wifi Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageCustomerReview"
android:src="#drawable/customerreview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3text"
android:text="CustomerReview Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagecardview"
android:src="#drawable/cardview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4text"
android:text="CardView Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagedemo"
android:src="#drawable/demo"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5text"
android:text="Test All Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </ScrollView>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ImageView beacon,cardview,customerreview,demo,wifi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beacon = (ImageView)findViewById(R.id.imageBeacon);
beacon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
if (!mBluetoothAdapter.isEnabled()) {
// Bluetooth is not enable :)
Dialog settingsDialog = new Dialog(MainActivity.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout
, null));
settingsDialog.show();
}
}
}
});
}
}
try this
Dialog settingsDialog = new Dialog(this);
settingsDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(R.layout.image_layout);
settingsDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
settingsDialog.setCancelable(true);
settingsDialog.setTitle("Title...");
settingsDialog.show();