Android EditText like Google Search EditText - android

Is there somewhere the code of Google Search in Android? The xml-layout would be enough for me. Or maybe there is a possibility to add a button to the right of the EditText just like adding an icon in the corner? Thanks.

<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bar"//set back ground for total look
android:orientation="horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Your hint"
android:drawableRight="#drawable/search"//give your search icon
android:id="#+id/editBox"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageSpeak"
android:background="#drawable/iconSpeak"//icon for speak
/>
</LinearLayout>

You have a LinearLayout with horizontal orientation where you can have an EditText, an ImageView with the search image and an ImageView for the microphone image. All of them should have the required background images cut in such way in order to seem as one. This is the general notion.
Regarding the source code, I can't help you!
Hope this helps!

Related

How to center text in google sign in button android

I am using the following code to put the google sign in button in my application. However the text in the button is off center. How can I make it centered?
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="visible"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp" />
By inspecting with the debugger and the decompiled class code, I've noticed:
the SignInButton class sets up the real button in setStyle. It uses inter-process binding APIs to create some class from some other library, and I couldn't identify that class nor locate its decompiled class code.
the inner button has side paddings set, which is larger on the side with G icon.
the G icon is displayed via a background drawable, and not the TextView drawableStart.
Thus, it seems like some manual padding is put on the real button, on the side with the G icon. Why they would do this, no idea. From the above, it's pretty safe to "fix" the padding after the button is inflated from your XML. I think this is also safe in the case of RTL, since the padding on the side with the icon is always larger, I think (or I sure hope so, somebody please let me know if this is broken in RTL):
loginBinding!!.googleSignInButton.getChildAt(0)?.let {
val smaller = Math.min(it.paddingLeft, it.paddingRight)
it.setPadding(smaller, it.paddingTop, smaller, it.paddingBottom)
}
That's Kotlin, of course.
Better create a button by yourself.
I always prefer this approach because i can develop any kind of google login button as i want.
<RelativeView
android:height="wrap_content"
android:width="match_parent"
android:marginLeft="20dp"
android:marginRight="20dp">
<ImageButton
android:parentRight="true"
android:id="google_icon"
android:background="#null"
android:padding="10dp"/>
<TextView
android:id="google_text"
android:height="wrap_content"
android:width="match_parent"
android:centerHorizontal="true"
android:text="Google Login"
android:padding="10dp"/>
</RelativeView>
Above is the structure of the code that you can use exactly to achieve what you want.
Just use your own custom view button instead of using their built-in button. BUT you need to follow the guideline. Even facebook button i custom to my need..
<RelativeLayout
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:layout_gravity="center"
android:background="#drawable/border_radius_white"
android:clickable="true"
android:id="#+id/google_signin" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/g_logo"
android:adjustViewBounds="true"
android:layout_gravity="center_vertical"
android:padding="12dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:typeface="normal"
android:textSize="#dimen/log_button_size"
android:text="#string/text_sign_in_with_google"
android:textStyle="bold"
android:textColor="#color/scGrey"/>
</RelativeLayout>
An easy way I got around this was to add spaces after my text.. so Instead of
android:text="Connect with Google"
I changed it to
android:text="Connect with Google_____________"
replace the underscores with spaces
however this was using the custom button "com.shobhitpuri.custombuttons.GoogleSignInButton"
Use gravity to fix the center of text:
<com.google.android.gms.common.SignInButton
......
android:gravity="center_vertical|center"
...... />

Relative Layout - Automatic wrapping

I have the following code snippet:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/collected_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/card_text_color"
android:textSize="#dimen/card_headline_textsize"
android:layout_marginBottom="#dimen/card_headline_marginBottom"
android:text="Foo" />
<ImageView
android:id="#+id/collected_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="140dp"
android:background="#android:color/holo_red_dark"
android:adjustViewBounds="true"
android:layout_below="#id/collected_item_title"
android:layout_marginEnd="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/collected_item_image"
android:layout_below="#id/collected_item_title"
android:text="Foo"
android:textColor="#color/card_text_color" />
</RelativeLayout>
I like to have the ImageView on the left and the second TextView either on the right of this image or unter the image, dependent on the size of the image.
The image should grow, until it reaches a maximum height of 140dp.
How can I automatically wrap the text if the image get's too width?
Unfortunately I have no idea at the moment how to do it.
Yes I can do it programmatically, but I like to reach the goal only with xml.
The wrapping RelativeLayout doesn't have to be a RelativeLayout, if this behaviour is possible with an other layout.
It sounds like you need a FlowLayout. Android does not provide one out-of-the-box, but check out this answer. How can I do something like a FlowLayout in Android?
Thanks to the answer of chessdork, I found the flexbox layout of google.
It gets provided by the following git repository.
https://github.com/google/flexbox-layout

Hint and Text in editText at same time

I just need an editText in which i can set Text and hint at the same time.
e.g i want user to enter in editText string like user#1234
in this string user# should be text after that numbers will vary so that 1234 should be show as hint when user try to enter cursor will go after # and 1234 hint will gone when user type a character.
Please guide me how to do this.
Thanks
I managed to achieved this with bit of tricks and playing with margin and padding
This is what I did
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="user#" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="1234"
android:paddingLeft="40dp"
android:textSize="14sp" />
</RelativeLayout>
Hope this will help you out
This is not possible in the Android's default EditText but if want to achieve this any how, you will have to work a bit.
You can use this library called Masked-EditText. Read the documentation and understand how you can use it to solve your purpose. Hope that helps.
[EDIT]
I've got one more trick that you can definitely use. Implement an onChangeListener on the edit text. Every time it is called, run a function. The function should get the text in the editText and get the substring (first 5 char). If the substring matches "user#" then do not do anything. Else replace the text in editText with "user#". Easy hah!
You can do this in 2 ways
#1
Place an Image with user# as drawableLeft to your EditText
#2
Use a RelativeLayout to place a TextView and EditText one above the other so that it shows text in TextView as hint in EditText as below :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="user#"
android:textColor="#aaaaaaaa"
android:textSize="30dip" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_toRightOf="#+id/textView1"
android:background="#00000000"
android:textSize="30dip">
</EditText>

Clickable Button (or any View) inside EditText in android

I want to have a Button or a clickable View in my EditText so that I can perform some action on click of it. I was able to put a drawable inside my EditText thanks to Marcosbeirigo for this answer. But, now I want to make it clickable so that I can perform some action on it. I know this is possible as HTC uses buttons inside EditText in their stock sms app as shown in the following image-
In my case, the button will be positioned anywhere, can be in the center also. But the main thing is how can I put a button in EditText?
Use RelativeLayout. The Send and Attach buttons are simple Android Buttons and the 32/160 is a TextView. Put the buttons and the textview on the EditText object, play with the layout arrangments and set some right padding to the EditText object so that the text inside it won't go under the buttons.
You don't need any drawable and listening to the click event of the android buttons is not a question anymore.
Its absolutely correct
Use this , It worked for me -
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/id_search_EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:paddingRight="40dp"
android:hint="Enter your feelings and connect" />
<ImageButton android:id="#+id/id_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/id_search_EditText"
android:layout_alignBottom="#+id/id_search_EditText"
android:layout_alignRight="#+id/id_search_EditText"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
I think you try to search set click event for compound drawable. You can find some solutions here
handling-click-events-on-a-drawable-within-an-edittext
there is no button inside editText It's just an editText with white background so you don't see it's margins and a simple layout arrangement.
The only possible solution is to use a RelativeLayout that allow you to put also Views in overlay to others. Other Layout wont allow you to do such things.
Also I found this tutorial: http://developer.android.com/resources/articles/layout-tricks-merge.html maybe it can helps you :)
Use this this code may work.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/REFReLayTellFriend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editext_rounded"
android:drawableLeft="#android:drawable/ic_menu_search"
android:gravity="start"
android:hint="Search"
android:singleLine="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtSearch"
android:background="#drawable/ic_action_content_filter_list"/>
</RelativeLayout>
</LinearLayout>

What is the best place to put a Log In button?

I have a log In page with username and password fields. I would like to know the best place to put the log-in button below them. Should it be left-aligned, centered, right-aligned or fill the entire width of the parent?
Is there a industry standard or best practice for Android Log In Buttons?
An idea would be to align them below the edit text views that will be completed. That's the most elegant way to do it.
You can try something like this
Or maybe something like this one
I would say put the login button below the fields. And center it, filling the same amount of space as the fields. This would look the best and would show up great in landscape and portrait.
A lot of companies put a lot of research into the best UI layouts.
The basic layout for login activity that I stumble upon everywhere in a books looks like this:
<TextView android:id="#+id/userNameLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Username: "
android:layout_alignParentTop="true" />
<EditText android:id="#+id/userNameText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameLbl" />
<TextView android:id="#+id/pwdLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameText"
android:text="Password: " />
<EditText android:id="#+id/pwdText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/pwdLbl" />
<Button android:id="#+id/btn" android:onClick="doClick"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Login" />
So it's pretty much similar to what #Arkde tried to show you in the second link.
Hope this helps.

Categories

Resources