How to add Parent appbar to child layout in Android Material design

We have to just add

app:layout_behavior="@string/appbar_scrolling_view_behavior"

at the child layout parent layout like Relative or Linear Layout.

example:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&quot;
xmlns:app="http://schemas.android.com/apk/res-auto&quot;
xmlns:tools="http://schemas.android.com/tools&quot;
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.resturant.vivaatech.resturantapp.Activities.ReportActivity"
tools:showIn="@layout/activity_report">

Advertisements

How to prevent soft keyboard from pushing up items

On Menifest just paste it :

android:windowSoftInputMode="adjustPan"

Details :
http://stackoverflow.com/questions/4207880/android-how-do-i-prevent-the-soft-keyboard-from-pushing-my-view-up

android edittext focus

Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer.

Change default behaviour of directional navigation by using following XML attributes:

android:nextFocusDown="@+id/.."
android:nextFocusLeft="@+id/.."
android:nextFocusRight="@+id/.."
android:nextFocusUp="@+id/.."

Besides directional navigation you can use tab navigation. For this you need to use

android:nextFocusForward="@+id/.."

To get a particular view to take focus, call

view.requestFocus()

How to add EditText keboard done button

android:imeOptions="actionDone"
android:singleLine="true"

add this two line on EditText

example:

<EditText
android:imeOptions="actionDone"
android:singleLine="true"
android:hint="PASSWORD"
android:paddingLeft="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/round_edittext_corner"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/editText_password_from_loginByEmailAddress"
android:layout_below="@+id/editText_email_from_loginByEmailAddress"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText_email_from_loginByEmailAddress"
android:layout_alignEnd="@+id/editText_email_from_loginByEmailAddress" />

How to add show navigation drawer with button click

  1. Take Button and implement click event
  2. Take navigation drawer and make it findViewById
  3. openDrawer(Gravity.Right) into button Click event .

 

DrawerLayout mDrawerLayout;
Button mButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mButton= (Button) findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mDrawerLayout.openDrawer(Gravity.END);

        }
    });


}

4 . if we want to make navigation back




add this to oncreate method

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(Gravity.RIGHT)) {
        drawer.closeDrawer(Gravity.RIGHT);
    } else {
        super.onBackPressed();
    }
}