Android avoid soft keyboard when startup - android-layout

Below is a layout displaying a EditText at the top and a listview below it.
when the layout starts, the EditText will be in focus and the keyboard is open by default.
how can i avoid opening the keyboard until i touch the EditText intending to start typing?
thank you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/White"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/title"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:hint="#string/Search"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:selectAllOnFocus="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/Gray"
/>
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cacheColorHint="#android:color/transparent"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<Button
android:id="#+id/btn_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Add"
android:onClick="onAdd"/>
</LinearLayout>

It would help . Just add a line in your manifest
<activity
android:name="com.example.activity"
android:windowSoftInputMode="stateHidden" // Add this to your manifest
android:label="#string/something">
</activity>

Related

Image won't center with android:layout_centerHorizontal

my image wont center using the code "android:layout_centerHorizontal" even using gravity wont solve it. Is there any other way or are there wrong inputs in my relativelayout and scroll view.
scale layout bounds
landscape view of with scale layout bounds
screen size 768x1280 nexus api23
I am not having problems with android version 4 maybe this is api related? since my minimum sdk is android version 2?
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.capstone.jmilibraryapp.Login">
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/etUsername"
android:hint="Enter Sr-Code"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_centerHorizontal="true"
android:layout_width="500dp"
android:layout_height="200dp"
android:src="#drawable/jmilogo"
android:id="#+id/imageView3"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/etPassword"
android:inputType="textPassword"
android:hint="Password"
android:layout_below="#+id/etUsername"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/bLogin"
android:text="Log In"
android:layout_below="#+id/etPassword"
android:layout_alignLeft="#+id/etPassword"
android:layout_alignStart="#+id/etPassword" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Log In as Guest"
android:id="#+id/guest"
android:layout_marginTop="20dp"
android:layout_below="#+id/bLogin"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Log In as Guest"
android:id="#+id/testinguser"
android:layout_marginTop="20dp"
android:layout_below="#+id/guest"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</ScrollView>
Probably your image donĀ“t have the same ratio of your ImageView, you can check it enabling showLayoutBounds in the developer tools in the device. You will see the real size of the imageView.
To solve that you can make you ImageView to be proportionally to your ImageView or ad a scaleType="fitCenter" to your ImageView.
Try below xml this is work with me..
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/school" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1">
<EditText
android:id="#+id/etUsername"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Enter Sr-Code" />
<EditText
android:id="#+id/etPassword"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#+id/etUsername"
android:layout_centerHorizontal="true"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="#+id/bLogin"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/etPassword"
android:layout_alignStart="#+id/etPassword"
android:layout_below="#+id/etPassword"
android:text="Log In" />
<TextView
android:id="#+id/guest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Log In as Guest"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="#+id/testinguser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/guest"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Log In as Guest"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

Ripple on android.support.v7.widget.CardView when inflating ListView

I am inflating a ListView with a CardView layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.13"
android:padding="16dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/primary_text" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="112"
android:layout_marginRight="10dp"
android:padding="16dp"
android:paddingLeft="20dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/secondary_text" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0.04"
android:elegantTextHeight="false"
android:padding="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/primary_text" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="129"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:padding="16dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="true" />
</TableRow>
</TableLayout>
</android.support.v7.widget.CardView>
and here is my ListView layout :
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/listView"
android:visibility="invisible"
android:paddingBottom="0dp"
android:background="#color/grey"
android:layout_gravity="center_horizontal|top"
android:divider="#color/white"
android:cacheColorHint="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:fastScrollEnabled="true"
android:layout_marginRight="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
The issue here is that I can't have the ripple effect on the card (I can only have it under the card) as you can see it here :
screenshot link
I've tried to put
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
on the cardview, but if I do this, I can't click on the card anymore (the onClick() function doesn't trigger anymore)
Would really appreciate some help understanding this.
It looks like you were close by adding the clickable and background, but you likely just need to select the right view to put the onClick listener on.
Did you try this?
view.findViewById(R.id.card_view).setOnClickListener(new View.OnClickListener)
view would be your LinearLayout with the id of lay.

Why doesn't my layout resize using a Graphical Layout?

I have added supports-screens to manifest, all UI elements values are in dip.
Why then I'm changing screen type in Graphical Layout my layout doesn't re-sizes?
I'm using LinearLayout, maybe better way is RelativeLayout?
Please help;
My Layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#000000">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20dip"
android:textStyle="bold"
android:layout_centerInParent="true"
android:text="Login" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/Image"
android:layout_width="280dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip"
android:layout_height="35dip"
android:src="#+drawable/logo_big"/>
<EditText
android:id="#+id/LoginName"
android:hint="Email"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:inputType="textEmailAddress"/>
<EditText
android:hint="Password"
android:layout_marginTop="0dip"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:inputType="textPassword"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:password="true"
android:id="#+id/Password"/>
<Button
android:id="#+id/LogIn"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="#+string/LogIn"/>
<TextView
android:id="#+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:gravity="center"
android:layout_marginTop="10dip"
android:textStyle="bold"
android:textSize="18dp"
android:text="#+string/DontHaveAnAccount"/>
<Button
android:id="#+id/SingUpNow"
android:layout_width="fill_parent"
android:layout_marginTop="10dip"
android:layout_height="45dip"
android:src="#+drawable/gray_button"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="#+drawable/primary_button"
android:clickable="true"
android:text="#+string/SingUpNow"/>
<Button
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_marginTop="10dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:id="#+id/ForgotYourPassword"
android:background="#+drawable/secondary_button"
android:text="#+string/ForgotYourPassword"/>
</LinearLayout>
</LinearLayout>
Help;
This tips maybe help you...
Avoid the use of graphical layout, just check you code there will be some hard code value or maybe there Absolute Layout..
To re-size the screen layout use Relative Layout... that will be fit for all screen..

How to set Focus on top Item?

I have one scroll view and but while I am running the code I found that some items in top are hides.
I want to show this scroll view from top most. please help me.
code is here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:scrollX="0px">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo"
android:focusable="true"
android:layout_marginTop="1dip" />
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/jvdbanner" />
<ListView
android:id="#+id/main_list"
android:layout_width="fill_parent"
android:layout_height="279dip"
android:background="#84CFE7"
android:cacheColorHint="#00000000"
android:divider="#000000"
android:dividerHeight="1dip"
android:focusable="false"
android:fadingEdge="none"
android:scrollbars="none" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginTop="5dip"
android:background="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:text="Copyright # 2012- JVD Properties, Inc."
android:textColor="#ffffff"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"
android:text="All Rights Reserved."
android:textColor="#ffffff"
android:textSize="13sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Just Try this code..hope it works for you
final ScrollView main = (ScrollView) findViewById(R.id.scrollView1);
main.post(new Runnable() {
public void run() {
main.scrollTo(0,0);
}
});

Android Layout - Dual Horizontal Scroll views

Is it possible (anything's possible, right!) to create dual horizontal scroll views on one layout screen?
As an example....I would like two (or three) row or icons that scroll independently. I see this type of behavior on apps like Pulse.
Help with layout code please... here is my single hor. scroll...
<?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="match_parent"
android:orientation="vertical" >
<HorizontalScrollView android:layout_height="100dp" >
<ImageButton
android:id="#+id/ImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon1" >
</ImageButton>
<ImageButton
android:id="#+id/ImageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon2" >
</ImageButton>
</HorizontalScrollView>
<HorizontalScrollView android:layout_height="100dp" >
<ImageButton
android:id="#+id/ImageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon3" >
</ImageButton>
<ImageButton
android:id="#+id/ImageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon4" >
</ImageButton>
</HorizontalScrollView>
</LinearLayout>
****Updated Code still not working... Maybe the height/width properties?
Here is solution this is working fine
<?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="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_height="100dp"
android:layout_width="100dp">
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content">
<ImageButton
android:id="#+id/ImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" >
</ImageButton>
<ImageButton
android:id="#+id/ImageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" >
</ImageButton>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView android:layout_height="100dp"
android:layout_width="100dp" >
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content">
<ImageButton
android:id="#+id/ImageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/ImageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" >
</ImageButton>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
try this enjoy...
Just put two or more scrolls in one LinearLayout
<LinearLayout
android:orientation="vertical" ...>
<HorizontalScrollView android:layout_height="100dp" .../>
<HorizontalScrollView android:layout_height="100dp" .../>
...
</LinearLayout>

Resources