When aplying exposed dropdown menu style for a dropdown menu on android studio my activity_main.xml disappears - android

I am trying to implement a dropdown menu on my app but anytime i try to choose any material option for style it makes the whole activity_main.xml disappear.
I have done it before in other projects that i use to test things before implementing in the final app and they work, i looked for any differences between projects but i dont find any.
this is the code snippet in the activity_main.xml
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="1">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="none"
android:text="Chose level and press play"
android:gravity="center"
android:fontFamily="#font/gomarice_coffee_jelly_umai"
android:textSize="30sp"/>
</com.google.android.material.textfield.TextInputLayout>
Here is the tutorial I followed: https://www.geeksforgeeks.org/exposed-drop-down-menu-in-android/
photo so you can have an idea
I have tried every materialDesign with the name dropdownmenu.
What I expect is to display a dropdown menu.
Im also having problem with other .xml file needed for the dropdownmenu
This file has a disappeared background, so maybe it has something related
This is the first time i ask, hope the problem is clear enough, and sorry for the language mistakes, i'm from Spain.

I think your issue is in AutoCompleteView.
The android:layout_height should be wrap_content and not match_parent.
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
/>

Related

How to control the drawing order of overlapping elements android activity?

I think I have tried and researched enough, if not everything, yet I just can't get the two icons on the right get displayed in android emulator.
The strange thing is, that they are perfectly visible in design window.
Moreover, with similar/same GUI design, other activities display all my elements just fine.
I already know well, that how views overlap on screen depends on order of elements as I place them in the 'Component Tree' of Android Studio IDE.
Correctly looking design in Android Studio:
Missing icons on the right in emulator:
Moreover, the app in missing the title, which could be caused by an inappropriate parent activity class (its Activity which I changed from AppCompatActivity as I spent quite some time with the AS Designing tool).
How else can I control the order of elements when they overlap?
Or what weird Android concept am I still missing?
Or what has changed since all worked fine for me?
Below is the code XML for app design:
<?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="com.sbm.bc.smartbooksmobile.ActivityTeacherHwkCheckByTask">
<ImageView
android:id="#+id/Problems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginTop="57dp"
android:elevation="24dp"
android:visibility="visible"
app:srcCompat="#drawable/ic_problems" />
<ImageView
android:id="#+id/Talar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="42dp"
android:layout_marginTop="57dp"
android:elevation="24dp"
android:visibility="visible"
app:srcCompat="#drawable/ic_menu_talar" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_dark"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="45dp"
android:background="#android:color/holo_blue_bright">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp"
android:visibility="visible">
<LinearLayout
android:id="#+id/ListOfTaskRows"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="24dp"
android:orientation="vertical"
android:visibility="visible">
</LinearLayout>
</ScrollView>
</TableRow>
<TextView
android:id="#+id/Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="63dp"
android:allowUndo="false"
android:elevation="20dp"
android:ems="10"
android:text="Ăšloha"
android:textAlignment="center"
android:textSize="18sp"
android:visibility="visible" />
</RelativeLayout>
I think you are missing the fact that the RelativeLayout children are drawn in front of each other if they overlap. In your case you have a TableRow whose width is match_parent - it fills the parent's width but as it's added after the image views it's drawn in front of them.
You could constrain the table's width so that it leaves room for the images by setting it's layout_alignEnd attribute to the id of your left-most image, so that the table would end where the image begins.
Well, believe it or not the reason for missing icons was, that I decided to derive my app from plain Activity and not AppCompatActivity as I had it before.
So I have restored my activity to extends AppCompatActivity again and lo and behold.. It works.
This of course also enabled the Activity title again.
As its a pure nonsence (another one) and my time wasted counts already in days (not only this issue, but many other crappy designs and apparent bugs in ADT), I've just decided to abbandon native Android development in the near future and switch back to Xamarin/C# instead. (I've started my Android development from C# Xamarin 4 years ago and only left because of insufficient HW access support at that time).
Howhg !
For user of "Material Design":
Another simple workaround is using "elevation" property of any GUI element.
By increasing this value, one can force to draw this element on foreground over those with lower elevation.
As a bonus (or drawback), you get shading around your elevated GUI element according to how much you have elevated.
I wonder how much this feature prolongs rendering time
Another question is min supported API version. (Did not find it right away..)

How to make a WhatsApp like `RecyclerView`?

This may be possible of duplicate question i have tried all things none of it works i need to make whatsapp like chat model using RecyclerView and at the bottom EditText and a Button bottom my problem is i can have EditText and bottom at the bottom but i need scroll to view that EditText and Button, what i should have when user enter that page EditText and Buttonb should appear without scrolling and one more problem there is lots of space between two items in thatRecyclerView` how to reduce that space let me post what i did so far:
My Recyclerview ChatLayout:
<?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.support.v7.widget.RecyclerView
android:id="#+id/constraint_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="4">
<EditText
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Message"
android:lines="1" />
<Button
android:id="#+id/btn_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Send" />
</LinearLayout>
</RelativeLayout>
How to do this as am new for android development someone please help me!
You should change the android:height in layout that u use in your RecyclerViewAdapter to wrap_content
And also in your manifest
<activity
...
android:windowSoftInputMode="adjustPan"
...
></activity>
Their are many libraries out there.This library is a sample Android App which can be used as a starter application for a chat application.You can take reference or implemented this library in your project
check your row item(layout xml file) which is used in your viewholder. I think you have used match_parent in your parent view. Make it as wrap_content.
For that scrolling issue, check your code for smoothScrollToPosition(int). may be you have used this method in your code.

Adding padding on android AutoCompleteTextView popup

For the last two hour and a half i had been trying to do something really simple: change the padding in the Android's AutoCompleteTextView's popup (the one that shows the auto complete options).
i'm trying to do this because the item in my app has the height of the text (i'm not sure why), so i want to make it easier to click on. But every think i could find didn't work at all.
So i really would be glad if anyone could spot a light in this problem or give an alternative solution.
And just for the record, i'm using android studio, and i had removed the support API (since my min API is 16), so my app is using 100% native resorts only.
I just found a way to make it, i had to make a custom view layout with an textview already including the item's padding. Than i created a custom adapter with uses this layout.
The layout goes like this
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_margin="0dp"
android:paddingLeft="#dimen/thin_margin"
android:paddingRight="#dimen/thin_margin"
android:paddingTop="#dimen/list_1line_item_padding"
android:paddingBottom="#dimen/list_1line_item_padding"/>
And in the custom adapter just used it in the getView method
itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_15"
android:paddingBottom="#dimen/dp_15"
android:id="#+id/parentid">
<AutoCompleteTextView
android:id="#+id/address_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_gray_bg"
android:drawableRight="#drawable/icon_search_smaller"
android:gravity="center_vertical"
android:hint="Start typing location"
android:inputType="textCapWords"
android:popupBackground="#drawable/auto_location_popup_bg"
android:textColor="#color/black"
android:textColorHint="#color/dark_grey"
android:textSize="16sp"
android:visibility="visible"
android:dropDownWidth="wrap_content"
android:dropDownAnchor="#+id/parentid">/>
<requestFocus />
</RelativeLayout>
</RelativeLayout>
define another relative layout wrapping only the autocomplete textview and the button. look at this link
Android layout padding is ignored by dropdown

EditText not showing up when Activity holds multiple fragments

For the few people looking at my previous similar question, I deleted it and moved it here to be a more specific question now that I have a greater insight to the problem.
I have an Activity that holds one fragment on my standard phone, and holds two fragments on larger devices (tablets). The Activity holds the options menu, as well as the EditText. When I use my phone, everything loads fine. When I use my tablet, the EditText is not shown in the Activity. Here is the .xml files.
Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xlmns:tools="http://schemas.android.com/tools
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="8dp"
android:orientation="vertical" >
<EditText
android:id="#+id/trips_editText_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/searchClients"
android:inputType="text|textNoSuggestions"
android:visibility="visible" >
<requestFocus />
</EditText>
<fragment
android:id="#+id/trips_list"
android:name="com.ib.dfm.TripsListFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:context=".TripsListActivity"
android:layout="#layout/trip_list_item" />
</LinearLayout>
Can anyone figure out why the EditText will not show up on my tablet? Also, if I try and access it programatically with findViewById I get null. Thanks.
You most likely have multiple layouts defined for your Activity and with tablet the xml file does not contain the EditText
You use fill_parent which has become deprecated, use match_parent instead. Hope it helps.

Add drawable to EditText's top|left corner

I know that in Android we can use function setCompoundDrawables(..) to add drawable.
My problem is that my EditText is multy-lines and i want to put drawable in EditText's top|left corner. But using at setCompoundDrawables() function, only give choice to put drawable in specific side.
Is it possibility at Android API to Do it?
Seems it's impossible to do it with only EditText / TextView without anyside effect and additional views (I've provided the way at the end, but it needs more work with image and can be not applicable for every phone, because of different edit text backgorunds depending of manufature). The same question have been asked already many times: here and here for example.
Per my understanding the easiest and fastests way might be not as suggested in above questions (by usage of RelativeLayout), but just using FrameLayout the following way (You'll have 2 views vs 3 view using RelativeLayout+ImageView):
Make your icon 9patch (using 9patch tool). E.g. you have the following icon initially:
Then You can convert it to the following one:
(You can see black pixels which shows area to be stretched with view and areas for content)
Using the following xml:
<!-- Main activity layout -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Edit text with drawable at top left -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/icon_9patch">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit"
android:hint="Enter text"
android:maxLines="10"
android:inputType="textMultiLine" />
</FrameLayout>
</RelativeLayout>
Gives the following result (I've added multiple lines of text):
Moreover, it's even possible to comply the task with only EditText (but You might loose default EditText background which might not be good, however You can include it into your ning-patch image; but it will still be the same on all phones instead of native one).
The following xml also works fine:
<!-- Main activity layout -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Edit text with drawable at top left -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit"
android:hint="Enter text"
android:maxLines="10"
android:inputType="textMultiLine"
android:layout_alignParentBottom="true"
android:background="#drawable/icon_9patch" />
</RelativeLayout>
Give the following result (note that default frame for edit has disappeared):
Try this one :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_10"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/map_mark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/scale_10"
android:gravity="top"
android:text="TEXT HERE"/>
</LinearLayout>

Categories

Resources