I want to set height of Alert dialog in my App. Since i use more than 10 fields inside the alert dialog to fill the data with which set positive and set negative button goes invisible . Now i want to decrease the height of alert dialog.I use getwindow.setlayout method but it is still at the same height.
package com.clone.tracking.unnamed.mytraining;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.clone.tracking.unnamed.mytraining.Model.Student;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.rengwuxian.materialedittext.MaterialEditText;
public class AdminControl extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
RelativeLayout rootLayout;
FirebaseDatabase db;
DatabaseReference students;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_control);
db=FirebaseDatabase.getInstance();
students=db.getReference("Students");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showStudentRegistrationDialog();
}
});
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.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
private void showStudentRegistrationDialog() {
final AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle("REGISTER");
dialog.setMessage("Please fill All Fields");
//AlertDialog alertDialog = builder.create();
LayoutInflater inflater= LayoutInflater.from(this);
View student_layout=inflater.inflate(R.layout.layout_details,null);
final MaterialEditText edtName=student_layout.findViewById(R.id.edtName);
final MaterialEditText edtRoll=student_layout.findViewById(R.id.edtRoll);
final MaterialEditText edtSemester=student_layout.findViewById(R.id.edtSemester);
final MaterialEditText edtFees=student_layout.findViewById(R.id.edtFee);
final MaterialEditText edtDob=student_layout.findViewById(R.id.edtDOB);
final MaterialEditText edtEmail=student_layout.findViewById(R.id.edtEmail);
final MaterialEditText edtPhone=student_layout.findViewById(R.id.edtPhone);
final MaterialEditText edtSex=student_layout.findViewById(R.id.edtSEX);
final MaterialEditText edtAddress=student_layout.findViewById(R.id.edtAddress);
final MaterialEditText edtPercent=student_layout.findViewById(R.id.edtPercentage);
final MaterialEditText edtcollege=student_layout.findViewById(R.id.edtCollege);
final MaterialEditText edtDepartment=student_layout.findViewById(R.id.edtDepartment);
dialog.setView(student_layout);
//this set the buttons below the pop up dialog
dialog.setPositiveButton("REGISTER", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
if(TextUtils.isEmpty(edtName.getText().toString()))
{
Snackbar.make(rootLayout,"Name is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtRoll.getText().toString()))
{
Snackbar.make(rootLayout,"Roll Number is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtSemester.getText().toString()))
{
Snackbar.make(rootLayout,"Semester is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtFees.getText().toString()))
{
Snackbar.make(rootLayout,"Fee detail is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtDob.getText().toString()))
{
Snackbar.make(rootLayout,"Date of Birth is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtEmail.getText().toString()))
{
Snackbar.make(rootLayout,"Email address is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtPhone.getText().toString()))
{
Snackbar.make(rootLayout,"Phone Number is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtSex.getText().toString()))
{
Snackbar.make(rootLayout,"Sex is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtAddress.getText().toString()))
{
Snackbar.make(rootLayout,"Address is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtPercent.getText().toString()))
{
Snackbar.make(rootLayout,"OverAll Percentage is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtcollege.getText().toString()))
{
Snackbar.make(rootLayout,"College Name is required",Snackbar.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(edtDepartment.getText().toString()))
{
Snackbar.make(rootLayout,"Department name is required",Snackbar.LENGTH_SHORT).show();
return;
}
Student student=new Student();
student.setName(edtName.getText().toString());
student.setRollno(edtRoll.getText().toString());
student.setSemester(edtSemester.getText().toString());
student.setFeedetails(edtFees.getText().toString());
student.setDob(edtDob.getText().toString());
student.setEmail(edtEmail.getText().toString());
student.setPhone(edtPhone.getText().toString());
student.setSex(edtSex.getText().toString());
student.setAddress(edtAddress.getText().toString());
student.setPercentage(edtPercent.getText().toString());
student.setCollegename(edtcollege.getText().toString());
student.setDepartment(edtDepartment.getText().toString());
String email= students.push().getKey();
students.child(email).setValue(student);
}
});
//this set the cancel button of the dialog
dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alert = dialog.create();
alert.getWindow().setLayout(600,400);
dialog.show();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.admin_control, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}