Popup window with recycler view background not working - android

I want to show popup window with Recycler view for menu.
popup window top right corner -> i am showing sort up arrow icon.
So i set the transparent background for popup window and showing recycler view with white background.
`menu.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));`
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvCategory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:elevation="10dp"
android:background="#drawable/popup_bg"/>
elevation is not working for recycler view. Its not looking like menu without border and elevation.
popup
Kindly help me to solve this issue.

To get your desired look you can modify your popup view xml like this:
<?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">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="6dp"
app:cardElevation="6dp">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvCategory"
android:layout_width="match_parent"
android:layout_height="200dp"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingEnd="1dp"
android:paddingBottom="5dp"
android:clipToPadding="false"
android:scrollbars="vertical" />
</androidx.cardview.widget.CardView>
</LinearLayout>
and in the code where you initialize your popup it should be like this(here mContext is your Activity):
PopupWindow mPopup = new PopupWindow(mContext);
View popUpView = mContext.getLayoutInflater().inflate(R.layout.your_popup_xml, null);
// other initializations
mPopup.setBackgroundDrawable(null);
mPopup.setContentView(popUpView);
mPopup.setFocusable(true);
mPopup.setClippingEnabled(true);

Related

Can't drag BottomSheet when clickable="true"? If not set clickable then click goes through it and fire on Recycleview item under it

Here is my Persistent BottomSheet
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/bs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bottom_sheet_background"
android:elevation="2dp"
android:padding="#dimen/base_margin"
app:behavior_hideable="true"
app:behavior_peekHeight="#dimen/bottom_sheet_peek_height"
app:layout_behavior="#string/bottom_sheet_behavior">
When User scrolls RecycleView, BottomNavigation hides and I reduce height of BottomSheet accordingly in RecycleView's addOnScrollListener using:
binding.rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
//148 = 80(bottom navigation) + 56(bottom sheet)
if (dy < 0)//scroll down
bottomSheetBehavior.setPeekHeight(136, true);
else if (dy > 0)//scroll up
bottomSheetBehavior.setPeekHeight(56, true);
}
After BottomNavigation is hidden and BottomSheet height is reduced, if BottomSheet is clickable,
(either through code binding.bs.bs.setClickable(false); or through xml android:clickable="true")
I can't drag it to expand. If it is not clickable, click event goes through it and user click on RecycleView item underneath it.
Even when its height is not reduced and it isn't clickable then also click event goes under it and fire on RecycleView item.
I also tried setting nestedScrolling, which allowed expanding but after that start creating issues when collapsing. :(
UPDATE:
I noticed BottomSheet drag not works when I set Bottomsheet clickable and its peekheight < 80 dp, ie the height of BottomNavigation.
Reference:
Why am I able to click "behind" the bottomsheet in Android?
I had same use case of having a recycler view inside a bottom sheet and here's what my Bottom sheet XML looks like. Please try to check if this works for you!
Apart from this, I did not actually get it why you want to reduce the height of the bottom sheet, as Bottom sheet has the behavior of self adjusting its height respect to the content inside it.
Please if possible share your use case so that it will be easier for the community to answer which gonna hit the bonsai. Thanks!
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="#color/transparent"
android:layout_height="match_parent"
android:paddingTop="50dp"
android:id="#+id/rootLayout"
>
<include
android:id="#+id/progress"
layout="#layout/item_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_sheet_rounded_background"
android:backgroundTint="#color/background_gray"
android:clipToPadding="true"
android:orientation="vertical"
app:layout_behavior="#string/bottom_sheet_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:id="#+id/title_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:height="24sp"
android:fontFamily="#font/silka_bold"
android:text="#string/error_select_prescription"
android:textColor="#color/text_color_semi_black"
android:textSize="16sp" />
<ImageView
android:id="#+id/iv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:src="#drawable/ic_close_btn_gray" />
</RelativeLayout>
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/btn_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/title_rl" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewPrescription"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingTop="#dimen/dimen_16dp"
tools:itemCount="10" />
</androidx.core.widget.NestedScrollView>
<include
android:id="#+id/btn_select_and_proceed"
layout="#layout/sticky_footer_design_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
val bottomSheet = dialog!!.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout
val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from<View>(bottomSheet)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
These all are the states which you can use to manipulate the height or basically the behavior of the BottomSheet.

Not able to set background color to a view in Kotlin

Edit: everything is fine with the code, Android Studio is not deploying changes to app version 4.1.3
Im trying to change the background color of view(Relative layout and rootView) at runtime
but its not working at all here is the code
rootview = findViewById(R.id.rootView)
rootview.setBackgroundColor(resources.getColor(R.color.backgroundColor2))
Layout code/file, I'm using relativeLayout as the main layout here which is overridden by another view completely
<?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:id="#+id/rootView"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/banner_container"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
<at.markushi.ui.CircleButton
android:id="#+id/button"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_launcher_foreground"
app:cb_color="#color/mainButtonColor1"
app:cb_pressedRingWidth="8dip" />
<at.markushi.ui.CircleButton
android:layout_width="64dp"
android:elevation="8dp"
android:layout_height="64dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
app:cb_color="#B71C1C"
app:cb_pressedRingWidth="8dip" />
</RelativeLayout>
If I set the background in XML it works fine
I think because you are using a Relative layout. So maybe, your relative layout is overridden or covered by another View (like view 2 is covered by view 1 and view 3 ). And when you change the background of view 2, this function worked but you don't see it because it is being covered by view 1 and view 3. You should try Liner Layout to replay.

Activity goes below status bar when soft keyboard opened

I am developing android custom keyboard and faced this problem. I am using candidates view to show suggestions. But in some cases when I am trying to use keyboard in applications Layout is going under status bar.
I have attached two images of problem. In both screenshots with red rectangle I have marked problem and with green rectangle Keyboard layout.
I have done research about this and find that it can be caused if Candidate view is not created in right way, but I have implemented candidate view as shown in examples.This is an Image from Facebook messenger
In this image keyboard is overlapping messengers edit text layout too.
Here are my code snippets from SoftKeyboard where i am creating candidates view.`
#Override public View onCreateCandidatesView() {
mCandidateView = new CandidateView(this);
mCandidateView.setService(this);
mCandidateView.setOnTranslitModeChangedListener(this);
return mCandidateView;
}`
my keyboard xml file
<?xml version="1.0" encoding="utf-8"?>
<com.innorise.kitkeysarmenian.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="50dp"
android:keyTextSize="18dp"
android:keyTextColor="#000"
android:background="#color/keyboardBackground"
android:keyPreviewLayout="#layout/preview"
android:popupLayout="#layout/keyboard_popup_layout"
android:drawingCacheQuality="high">
and here is my candidates view xml file`
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="5dp"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/candidatesList"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/candidateSwitch"/>
<TextView
android:textSize="18sp"
android:visibility="gone"
android:text="Translit is off."
android:gravity="center"
android:id="#+id/translitModeisOff"
android:layout_toLeftOf="#+id/candidateSwitch"
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.rm.rmswitch.RMSwitch
android:id="#+id/candidateSwitch"
app:switchDesign="slim"
app:switchBkgCheckedColor="#4ed736"
app:switchBkgNotCheckedColor="#cccccc"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
app:switchToggleCheckedColor="#aca2a2"
app:switchToggleNotCheckedColor="#aca2a2"
android:layout_width="50dp"
android:layout_height="35dp"/>
</RelativeLayout>
add this to your manifest :
<activity
android:name="activity.name"
android:windowSoftInputMode="adjustPan|adjustResize"/>

Dynamic content inside scrollview lost last view

I have ScrollView with LinearLayout and button inside:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/layout_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/card_color"
android:orientation="vertical"
android:padding="10dp">
</LinearLayout>
<Button
android:id="#+id/button_leave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/leave" />
</LinearLayout>
</ScrollView>
Then in code I add view to layout_list:
View view = LayoutInflater.from(this)
.inflate(R.layout.item_member, mLayoutMemberList, true);
If I add not many items, then button_leave is visible. But if I add a lot of items (more then showing on the screen) then button is not visible on the screen even if I scroll down.
Update:
Looks like it is bug of android.support.design.widget.CoordinatorLayout. I change it to simple linear layout and all work good.
Try like this:
I think layout view is working fine and try below code,
LayoutInflater inflater = context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.layout_list, null, true);

SearchView suggestions are showing over the widget

I'm using the searchview at the top of my activity positioned just below the action bar, the problem is that the suggestions are displayed over the searchview so the user cant see the typed the text
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.SearchView
android:id="#+id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.SearchView>
<RelativeLayout
android:layout_below="#id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map_container">
<!-- The map fragments will go here -->
</RelativeLayout>
</RelativeLayout>
no clue what the official answer even means. a work colleague aided me and I wanted to show how this can be achieved:
it can be done programatically by getting the textview as an AutoCompleteTextview:
imagine you have a searchview in xml like this:
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="10dp"
android:animateLayoutChanges="true"
android:paddingLeft="0dp"
app:closeIcon="#drawable/close_x_icon"
app:queryBackground="#drawable/search_bg_expanded"
app:searchHintIcon="#drawable/empty_drawable"
app:searchIcon="#null" />
then in code do this:
val searchText = searchView.findViewById<TextView>(android.support.v7.appcompat.R.id.search_src_text) as? AutoCompleteTextView
searchText?.dropDownAnchor = searchView.id
so once you cast it to an AutocompleteTextView you can change the anchor basically.
fixed by adding this view to the bottom of the relativelayout and setting it to the anchor
<View android:id="#+id/fragment_map.dropDownAnchor"
android:layout_below="#id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="0dp" />

Categories

Resources