I want to use SearchView that it the same to google play store SearchView like picture below but I don't know how do it.
May you show me sample code or google library?
Thank You!
try this my friend
add this dependency in gradle app file
compile 'com.android.support:cardview-v7:25.3.1'
now use below code
<android.support.v7.widget.CardView
android:layout_width="match_parent"
app:cardElevation="10dp"
app:cardUseCompatPadding="true"
android:layout_height="wrap_content">
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_edit"
android:drawablePadding="5dp"
android:background="#null"
android:drawableRight="#drawable/ic_delete"
android:hint="Search anything" />
</LinearLayout>
</android.support.v7.widget.CardView>
ask me in case of any query
Related
I'm using Android Studio and I'm new to this.
For some of the objects like the last button object, the system tells me "Hardcoded string 'Message', should use'#string' resource". What does this mean?
I've searched online and some say to use <resource> but I don't know what this means. How can I fix this?
For example, in the first ImageView, an error pops up here android:contentDescription="homeImage"
<?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="wrap_content"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView6"
android:layout_width="135dp"
android:layout_height="130dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="138dp"
android:contentDescription="homeImage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher_round"
tools:ignore="ImageContrastCheck" />
<TextView
android:id="#+id/textView"
android:layout_width="150dp"
android:layout_height="55dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="136dp"
android:text="TextView"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<Button
android:id="#+id/followButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:layout_marginEnd="88dp"
android:text="Follow"
app:layout_constraintEnd_toStartOf="#+id/messageButton"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<Button
android:id="#+id/messageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:layout_marginEnd="72dp"
android:text="Message"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
It's warning not an error.
And only to make it easier to reuse strings and also for translation
It is a warning that tells you that you would better use the #string xml file to have your texts at .
In Android studio, a resource is a localized text string, bitmap, layout, or other small piece of noncoded information that your app needs. At build time, all resources get compiled into your application.
for example your layout you are presenting above is a resource file that goes in #layout folder you also can use #drawable folder to save your images vectors ...
and there is plenty of other folders android studio provide to control your and to make it easier for you and for the system .
you might at the beginning find it hard but after some time you will like it .
for more information ,have a look at App resources overview
I need help.
At work, I was given a task to figure out why ScrollView overlaps part of the text. The layout is multi-layered, and I think the problem lies in this. I'm new to android studio and it's still hard for me to understand the relationships of all objects.
all the XML is here https://docs.google.com/document/d/1PaGIWPn2w6ubZraVpQfq8Rrqo0uCWYOiIbxnCWaIKTQ/edit?usp=sharing
below is a part of the code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left|center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:textColor="#color/mainBlackColor"
android:textSize="24dp"
tools:text="Сообщение" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/red"
android:lines="3"
android:paddingStart="3dp"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:paddingEnd="3dp"
android:paddingRight="3dp"
android:paddingBottom="2dp"
android:textColor="#color/mainTextColor"
android:textSize="18dp"
android:visibility="gone"
app:autoSizeMaxTextSize="18dp"
app:autoSizeMinTextSize="10dp"
app:autoSizeStepGranularity="4dp"
app:autoSizeTextType="uniform"
tools:text="Детали"
tools:visibility="visible" />
</LinearLayout>
</ScrollView>
Add android:scrollbarStyle="outsideOverlay" and padding_horizontal to your scrollView. This should solve your issue.
Part of my UI goes off-screen when installed on an actual android device. It uses the Google maps API. The "my location" button goes a little bit off screen.
Also the map doesn't cover the complete screen even though it does in the UI preview in Android Studio.
<LinearLayout xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="269dp"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/SearchLocationText"
android:hint="Search Location"
android:textCursorDrawable="#drawable/black_cursor"
/>
<Button
android:text="Search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/SearchButton"
android:onClick="onSearch" />
</LinearLayout>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context="com.anand.projectv10.MapsActivity1"
android:layout_height="519dp"
android:layout_width="382dp" />
You have a preview of what you are designing at android studio.So you will design something to cover that screen but note that every screen is not with the same dimensions(width/height/dpi). When you hardcore values there is a high possibility to make view positions go wrong in real scenarios.Values assigned based on ratios always stick fine.
You can use weightSum and layout_weight to achieve what you want without hard coding values
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5">
<EditText
android:id="#+id/SearchLocationText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:hint="Search Location"
android:inputType="textPersonName"
android:textCursorDrawable="#drawable/black_cursor" />
<Button
android:id="#+id/SearchButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="onSearch"
android:text="Search" />
</LinearLayout>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.anand.projectv10.MapsActivity1" />
</LinearLayout>
For further understanding Read
What is android:weightSum in android, and how does it work?
What does android:layout_weight mean?
I have four image icons that I need to display with Imagebutton or Imageview. The problem is when I use the following code, they all are aligned left leaving an empty space to the right.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/sale"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/shirt"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/women"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/technology"
android:layout_weight="1"/>
</LinearLayout>
How can I get them equally distributed on the linearlayout so that they fill the whole width?
I just managed to fix the issue. It seems I was needed to use android:layout_width"fill_parent" instead of android:layout_width="wrap_content". I tried this after #grwww suggested android:layout_gravity="fill" which was not the needed attribute. Then I got to learn about fill_parent
I need to display a ListView next to a Webview (like the Master/Detail sample), but I need to be able to sort the ListView in a different order (to display some items by category or by name for example), but I did not succeed to make it possible with tabs, dropdown menu or SectionPagerAdapter because the Master/Detail sample uses Fragment, and the TabHost is not a Fragment. I am a bit lost with what I should use.
To make it clear, I want to display it like that :
1
Is there some open source project that use this kind of view, or do your have some advice to perform that ?
You can do it also manually. Just make two list views on top of each other and change their visibilities so only one at a time will be shown.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="64dp"
android:layout_height="match_parent" >
<ListView
android:id="#+id/list_view1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/list_view2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<WebView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
This is just skeleton of you're UI that you can use.