popup window button not working - android

I am developing app having a popup window showing successfully but button inside is not working. When the button is click the event is not listening. The code is shown below.
private void showPopup() {
//LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup_layout,null);
mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
Button btn_popup_submit = (Button)customView.findViewById(R.id.btn_popup_submit);
Button btn_popup_cancel = (Button)customView.findViewById(R.id.btn_popup_cancel);
btn_popup_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "aaa", Toast.LENGTH_SHORT).show();
Log.d("LOG","aaaa");
}
});
btn_popup_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "bbbb", Toast.LENGTH_SHORT).show();
Log.d("LOG","bbbb");
}
});
if(Build.VERSION.SDK_INT>=21){
mPopupWindow.setElevation(5.0f);//5.0f
}
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, android.R.color.transparent)));
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.setTouchable(false);
mPopupWindow.update();
}
The pop up layout code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_custom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#5b5e93"
>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Sent."
android:textSize="20sp"
android:textColor="#color/colorWhite"
android:padding="25sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_above="#+id/editText"
android:layout_marginBottom="50dp"
android:background="#color/colorGray"
android:orientation="horizontal"></LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:textSize="16sp"
android:textColor="#color/colorWhite"
android:text="#string/email_sent" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:ems="4"
android:maxLength="4"
android:minLines="4"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btn_popup_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Submit"
android:textAllCaps="false" />
<Button
android:id="#+id/btn_popup_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Cancel"
android:textAllCaps="false" />
</LinearLayout>
</RelativeLayout>
The button names are btn_popup_submit and btn_popup_cancel.
I tried different methods but the problem. I don't know where is the problem facing. Please help me thanks.

Replace this line of code.Allow popWindow Touch.
mPopupWindow.setTouchable(false);
to
mPopupWindow.setTouchable(true);

Related

Dynamically added EditText is not visible when created

I have been reading about how to dynamically add an EditText field to my Linear Layout, every-time a user clicks a TextView (which has an onClick Listener attached).
I have had some mild success - I know that the EditText field is being created because when the button is clicked, all other elements move up as if something is being added to the screen.
My problem is that the EditText aren't visible and I haven't a clue why that is, so any help would be appreciated.
The the app isn't crashing so nothing to add in terms of the StackTrace and Log, as far as the app is concerned, everything is being created.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout 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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/facebookBlue"
android:orientation="vertical"
android:weightSum="1"
tools:context="com.test.practise.AddTeamMembers">
<android.support.design.widget.TextInputEditText
android:id="#+id/tv_teamNames"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/teamName"
android:textColor="#android:color/background_light"
android:textColorLink="#android:color/background_light"
android:textSize="30sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.26"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.47"
android:gravity="center"
android:text="Enter Player Names Below!"
android:textColor="#android:color/background_light"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:orientation="vertical"
android:weightSum="1">
<EditText
android:id="#+id/et_team_name1"
android:layout_width="232dp"
android:layout_height="37dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="#android:color/background_light"
android:ems="10"
android:hint="Team Name"
android:imeOptions="actionDone"
android:inputType="text"
android:paddingLeft="70dp"
android:singleLine="true"
tools:layout_editor_absoluteX="76dp"
tools:layout_editor_absoluteY="188dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:orientation="vertical"
android:weightSum="1">
<EditText
android:id="#+id/et_team_name2"
android:layout_width="232dp"
android:layout_height="37dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#android:color/background_light"
android:ems="10"
android:hint="Team Name"
android:imeOptions="actionDone"
android:inputType="text"
android:paddingLeft="70dp"
android:singleLine="true"
tools:layout_editor_absoluteX="76dp"
tools:layout_editor_absoluteY="188dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:orientation="vertical"
android:weightSum="1">
<EditText
android:id="#+id/et_team_name3"
android:layout_width="232dp"
android:layout_height="37dp"
android:layout_gravity="center"
android:background="#android:color/background_light"
android:ems="10"
android:hint="Team Name"
android:imeOptions="actionDone"
android:inputType="text"
android:paddingLeft="70dp"
android:singleLine="true"
tools:layout_editor_absoluteX="76dp"
tools:layout_editor_absoluteY="188dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/editTextGroupLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.07"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/tv_add_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="+ Add Name"
android:textColor="#android:color/background_light"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/facebookBlue"
android:gravity="center"
android:text="Ready to join!"
android:textColor="#android:color/background_light" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Below is the AddTeamMembers Class that calls the above XML
public class AddTeamMembers extends Fragment implements
View.OnClickListener
{
private SharedPreferences pref;
private TextView tv_teamNames, tv_add_name;
private LinearLayout mLayout;
//The below method must be overridden in order to implement a fragment -
this changes the lifecycle method
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_add_team_members,
container, false);
initViews(view);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// 0, Sets Shared pref mode to private
pref = getActivity().getPreferences(0);
tv_teamNames.setText(pref.getString(Constants.Team_Name, ""));
}
private void initViews(View view) {
tv_teamNames = (TextView) view.findViewById(R.id.tv_teamNames);
tv_add_name = (TextView) view.findViewById(R.id.tv_add_name);
mLayout = (LinearLayout) view.findViewById(R.id.editTextGroupLayout);
tv_add_name.setOnClickListener(this);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_add_name:
createEditTextView();
break;
}
}
#TargetApi(Build.VERSION_CODES.M)
public void createEditTextView() {
try{
//dynamically create new EditText when user clicks to add another
name
//target user using API 22 and above (lollipop and above)
EditText editTextView = null;
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.M) {
editTextView = new EditText(getContext());
}else{
Toast.makeText(getActivity(), "App is not supported on this
device",
Toast.LENGTH_LONG).show();
}
editTextView.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
editTextView.setLayoutParams(params);
mLayout.addView(editTextView);
}catch(Exception e){
Log.d(TAG, "Failed to create new edit text");
}
}
}
[![Before Button is clicked][1]][1]
[![I have clicked 2 add 3 EditText here to make it obvious whats happening]
[2]][2]
[1]: https://i.stack.imgur.com/DGoPd.png
[2]: https://i.stack.imgur.com/3LWcY.png

Buttons Overlap

I made a stopwatch using chronometer with four buttons but when i use the visibility modes to make stop and pause button appear they overlap.... Pls explain why...Below is the code.....
Assume the layout file with buttons in relative layout...
public class StopWatchFragment extends Fragment {
Chronometer chronometer;
Button startStopWatch;
Button stopStopWatch;
Button resetStopWatch;
Button pauseStopWatch;
Button resumeStopWatch;
private long lastPause;
//RelativeLayout relativeLayout;
private int check = 0;
public StopWatchFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.stopwatch_layout,container,false);
chronometer = (Chronometer) rootView.findViewById(R.id.stopwatch);
startStopWatch = (Button) rootView.findViewById(R.id.startStopWatch);
stopStopWatch = (Button) rootView.findViewById(R.id.stopStopWatch);
resetStopWatch = (Button) rootView.findViewById(R.id.resetStopWatch);
pauseStopWatch = (Button) rootView.findViewById(R.id.pauseStopWatch);
resumeStopWatch = (Button) rootView.findViewById(R.id.resumeStopWatch);
relativeLayout = (RelativeLayout) rootView.findViewById(R.id.parentRelativeLayout);
pauseStopWatch.setVisibility(View.GONE);
//final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(relativeLayout.getLayoutParams());
startStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
startStopWatch.setVisibility(View.GONE);
pauseStopWatch.setVisibility(View.VISIBLE);
if(check == 1){
resumeStopWatch.setClickable(true);
}
else{
resumeStopWatch.setClickable(false);
}
//params.setMargins(16,16,16,16);
//pauseStopWatch.setLayoutParams(params);
}
});
pauseStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
check = 1;
lastPause = SystemClock.elapsedRealtime();
chronometer.stop();
}
});
resumeStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(chronometer.getBase() + SystemClock.elapsedRealtime() - lastPause);
chronometer.start();
resumeStopWatch.setClickable(false);
}
});
stopStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.stop();
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
resumeStopWatch.setClickable(false);
}
});
resetStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.stop();
resumeStopWatch.setClickable(false);
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
}
});
return rootView;
}
}
This is the layout file pls refer for this....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
This is the way buttons work when click on start button
You are hiding the button, but you are still listening with the OnClickListener. Try adding:
pauseStopWatch.setOnClickListener(null);
Then, when you make your button visible:
pauseStopWatch.setOnClickListener(whatever);
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:visibility="gone"
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</LinearLayout>
</LinearLayout>
In the above, the pause button will be set to Gone. You make it visible later when user clicks start button

How to create custom dialog box with two button in android?

How to generate custom dialog box in android like this,
I want just like this.
How to generate it. please give me suggestion.
i have used below code for dialog box, what is the problem in my code?
I have not identify it. please share me any Idea.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video" />
</LinearLayout>
</RelativeLayout>
Please share me any Idea.
Thanks.
Simple, 1st need to create an newcustom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:layout_marginEnd="60dp"
android:layout_marginStart="60dp"
app:cardCornerRadius="8dp"
app:cardElevation="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Quit Earning?"
android:textColor="#android:color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. quit Earning?"
android:textSize="18dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmNo"
android:layout_marginRight="45dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="No"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmOk"
android:layout_marginLeft="50dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="Ok"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
</FrameLayout>
Then, in java file (in activity) paste this code
public class ViewDialog {
public void showDialog(Activity activity) {
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.newcustom_layout);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
FrameLayout mDialogNo = dialog.findViewById(R.id.frmNo);
mDialogNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Cancel" ,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
FrameLayout mDialogOk = dialog.findViewById(R.id.frmOk);
mDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Okay" ,Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
dialog.show();
}
}
Finally you can call it wherever you want.
ViewDialog alert = new ViewDialog();
alert.showDialog(CustomDialogActivity.this);
Inside your dailog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
open dimens.xml and add code mentioned below
<dimen name="thirty_dp">30dp</dimen>
<dimen name="ten_dp">10dp</dimen>
<dimen name="twenty_sp">20sp</dimen>
<dimen name="twenty_dp">20dp</dimen>
<dimen name="sixteen_sp">16sp</dimen>
open drawable and create btn_white.xml add code mentioned blow
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp"></corners>
<solid android:color="#android:color/white"></solid>
</shape>
open mainactivity.java and add the code mentioned below
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.dailog);
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.btn_cancel);
// if decline button is clicked, close the custom dialog
declineButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button videoButton = (Button) dialog.findViewById(R.id.btn_video);
// if decline button is clicked, close the custom dialog
videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
custom_dialog.xml
<?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="80dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Do you realy want to exit ?"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_yes"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Yes"
android:textColor="#5DBCD2"
android:textStyle="bold" />
<Button
android:id="#+id/btn_no"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:background="#android:color/white"
android:clickable="true"
android:text="No"
android:textColor="#5DBCD2"
android:textStyle="bold" />
</LinearLayout>
You can change your button by using
android:src=#drawable/image
You have to extends Dialog and implements OnClickListener
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes, no;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
c.finish();
break;
case R.id.btn_no:
dismiss();
break;
default:
break;
}
dismiss();
}
}
Call Dialog
CustomDialogClass cdd=new CustomDialogClass(Activity.this);
cdd.show();
Maybe try this method
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#color/colorPrimary"
app:cardCornerRadius="16dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_done_all"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorButtonNormal"
android:text="Tebrikler!"
android:layout_gravity="center_horizontal"
android:textSize="36sp"
android:padding="8dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnDialogCancel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Çıkış"
android:textColor="#FFF"
android:layout_marginRight="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/btnDialogOk"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Devam"
android:textColor="#FFF"
android:layout_marginLeft="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
main.java
Dialog dialog = new Dialog(context, R.style.CustomDialog);
LayoutInflater layoutInflater = LayoutInflater.from(context);
CardView cardView = (CardView) layoutInflater.inflate(R.layout.dialog, null);
dialog.setContentView(cardView);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
dialogBtnCancel();
private void dialogBtnCancel(){
mBtnDialogCancel = dialog.findViewById(R.id.btnDialogCancel);
mBtnDialogOk = dialog.findViewById(R.id.btnDialogOk);
mBtnDialogCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
mBtnDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
}

Hiding keyboard in fragments

I am having a fragment and in that fragment there is an add button which triggers a dialog when clicked . In that dialog I am having two edittext and two buttons. On click of save button dialog is dismissed. Now problem is that when I click on save button edit text keyboard closes and another keyboard pop up.(Edit text keyboard type is number while that popup after is alphabetical).I want to close this keyboard therefore I tried configChanges and this method
public static void hideKeyboard(Context ctx) {
InputMethodManager inputManager = (InputMethodManager) ctx
.getSystemService(Context.INPUT_METHOD_SERVICE);
// check if no view has focus:
View v = ((Activity) ctx).getCurrentFocus();
if (v == null)
return;
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
But none of this method works and I am also not having any edit text in fragment from which dialog appears.
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lin_add_dns">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="ADD DNS"
android:gravity="center"
android:background="#drawable/add_dns_title"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="20sp"
android:id="#+id/txt_add_dns"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="DNS NAME"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_marginRight="20dp"
android:id="#+id/et_name"
android:layout_gravity="center"
android:textColorHint="#999999"
android:textColor="#000"
android:focusableInTouchMode="true"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:hint="IP Address"
android:inputType="number"
android:id="#+id/et_ip"
android:layout_gravity="center"
android:digits="0123456789."
android:textColorHint="#999999"
android:textColor="#000"
android:maxLength="15"
android:focusableInTouchMode="true"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:text="Submit"
android:background="#drawable/textview_click"
android:textColor="#ffffff"
android:id="#+id/btn_submit"/>
</LinearLayout>
fragment.xml
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#ccc"
android:focusableInTouchMode="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:id="#+id/TopHeader"
android:text="Current WIFI Info"
android:paddingRight="15dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="20dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_weight=".50"
android:paddingRight="5dp"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textAlignment="gravity"
android:id="#+id/WiFiConnectLeft"
android:text="Wifi Name :"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textAlignment="gravity"
android:id="#+id/DefaultGatewayLeft"
android:text="Default Gateway :"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textAlignment="gravity"
android:id="#+id/DNS1Left"
android:text="Primary DNS :"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textAlignment="gravity"
android:id="#+id/DNS2Left"
android:text="Secondary DNS :"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textAlignment="gravity"
android:id="#+id/CurrentIPLeft"
android:text="IP Address :"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight=".50"
android:paddingLeft="5dp"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/WiFiConnectedText"
android:textAlignment="gravity"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DefaultGatewayText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DNS1Text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DNS2Text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CurrentIPText"/>
</LinearLayout>
</LinearLayout>
-<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHANGE DNS"
android:layout_gravity="center"
android:textAlignment="gravity"
android:id="#+id/MiddleHeaderText"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="#000"
android:textSize="20sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/tv_title"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginTop="10dp"
android:id="#+id/lin_primary"
android:gravity="center_vertical"
android:paddingRight="15dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/primary"
android:textStyle="bold"
android:textColor="#000"
android:id="#+id/PrimaryDNSText"
android:gravity="center"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:textSize="13sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1.2"
android:background="#000"
android:textColor="#ffffff"
android:inputType="numberDecimal"
android:layout_marginRight="10dp"
android:maxLength="16"
android:id="#+id/EDITDNS1"
android:gravity="center"
android:text=""/>
<Button
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.8"
android:text="BROWSE"
android:gravity="center"
android:background="#drawable/textview_click"
android:textColor="#ffffff"
android:id="#+id/BrowseDNS1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/lin_primary"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginTop="10dp"
android:id="#+id/lin_secondary"
android:gravity="center_vertical"
android:paddingRight="15dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/secondary"
android:textColor="#000"
android:id="#+id/SecondaryDNSText"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:textSize="12sp"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1.2"
android:background="#000"
android:textColor="#ffffff"
android:inputType="numberDecimal"
android:layout_marginRight="10dp"
android:maxLength="16"
android:id="#+id/EDITDNS2"
android:gravity="center"
android:text=""
/>
<Button
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.8"
android:text="BROWSE"
android:gravity="center"
android:background="#drawable/textview_click"
android:textColor="#ffffff"
android:id="#+id/BrowseDNS2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="3">
<Button
android:layout_width="0dp"
android:layout_height="40dp"
android:text="ADD DNS"
android:id="#+id/btn_add"
android:textColor="#ffffff"
android:background="#drawable/textview_click"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="40dp"
android:id="#+id/UpdateDNS"
android:text="Update"
android:background="#drawable/textview_click"
android:textColor="#ffffff"
android:layout_marginLeft="20dp"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="40dp"
android:id="#+id/ResetWifi"
android:text="RESET"
android:background="#drawable/textview_click"
android:textColor="#ffffff"
android:layout_marginLeft="20dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Dialog java code
addDns.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
android.support.v7.app.AlertDialog.Builder builder;
final android.support.v7.app.AlertDialog alertDialog;
TextView txt_add_dns;
Button btn_submit;
final EditText et_name, et_dns;
LayoutInflater inflater = getActivity().getLayoutInflater();
final View layout = inflater.inflate(R.layout.add_dns_dialog, (ViewGroup) getActivity().findViewById(R.id.lin_add_dns));
builder = new android.support.v7.app.AlertDialog.Builder(ctx);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
txt_add_dns = (TextView) layout.findViewById(R.id.txt_add_dns);
et_name = (EditText) layout.findViewById(R.id.et_name);
et_dns = (EditText) layout.findViewById(R.id.et_ip);
Fonts.setHelveticaFont(ctx, txt_add_dns);
btn_submit = (Button) layout.findViewById(R.id.btn_submit);
Fonts.setHelveticaFont(ctx, btn_submit);
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end > start) {
String destTxt = dest.toString();
String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
if (!resultingTxt.matches("^\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {
return "";
} else {
String[] splits = resultingTxt.split("\\.");
for (int i = 0; i < splits.length; i++) {
if (Integer.valueOf(splits[i]) > 255) {
return "";
}
}
}
}
return null;
}
};
et_dns.setFilters(filters);
btn_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fonts.setHelveticaFont(ctx, et_name);
Fonts.setHelveticaFont(ctx, et_dns);
et_dns.setRawInputType(InputType.TYPE_CLASS_NUMBER);
if (!et_name.getText().toString().equalsIgnoreCase("") && !et_dns.getText().toString().equalsIgnoreCase("")) {
String name = et_name.getText().toString();
String dns = et_dns.getText().toString();
IPAddressValidator iptester = new IPAddressValidator();
boolean valid = iptester.validate(dns);
if (valid) {
dataBaseHelper.addUserDns(name, dns);
// dnsListAdapter.notifyDataSetChanged();
alertDialog.dismiss();
hideKeyboard(getActivity());
} else {
Toast.makeText(ctx, "Invalid IP Address", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(ctx, "Please enter IP Address and DNS Name", Toast.LENGTH_LONG).show();
}
}
});
}
});
What's the issue here??
**EDIT:**After checking for each edit text individually I found that the keyboard from first editext didn't closes itself.So I added focus change listener and when it loses focus I called hide Keyboard.
I debugged line by line and everything works perfectly, debugger also enters hide keyboard method but that code is not able to hide keyboard. Is there any other method for hiding keyboard in fragments??
Is this problem with context that is passed in hide keyboard method ??Can we get context of an alert dialog in android because when I debug it showing context of Main Activity as I am passing getActivity() as parameter .Is this the issue??
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
create this methos infragment and call this method where u want to hide keyboard in your fragment.
Hiding Keyboard using method doesn't work for me. I added the code directly in submit button and that worked for me. Here is what I added
InputMethodManager im = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(et_name.getWindowToken(), 0);
InputMethodManager im1 = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
im1.hideSoftInputFromWindow(et_dns.getWindowToken(), 0);
Here et_dns and et_name are my edit text

Issue when using Scrollview inside Dialog

I am inflating a layout inside a dialog, which consist of a scrollview but the layout is not scrolling. I have referred so many questions from stackoverflow but then also its not working. My layout.xml is given below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/White"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:text="Update available"
android:textColor="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/upgrade_msg"
android:textColor="#000000" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_margin="3dp"
android:layout_weight="0.02"
android:src="#drawable/updateimg2" />
<Button
android:id="#+id/btn_upgrade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#color/White"
android:gravity="center"
android:text="Upgrade Now"
android:textColor="#color/Black" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/line_y_h" />
<Button
android:id="#+id/btn_remind"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#color/White"
android:gravity="center"
android:text="Remind Me Later"
android:textColor="#color/Blue" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/line_y_h" />
</LinearLayout>
</ScrollView>
Dialog code
public void show_Alert_version_custom(String str, final String url,
final String exitStatus)// use for
{
final Dialog dialog = new Dialog(Splash.this);
dialog.setContentView(R.layout.version_update);
dialog.setTitle(getString(R.string.alert_title));
Button dialogButton2 = (Button) dialog.findViewById(R.id.btn_remind);
dialogButton = (Button) dialog.findViewById(R.id.btn_upgrade);
ImageView viewLine = (ImageView) dialog.findViewById(R.id.imageView2);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {}
});
// if button is clicked, close the custom dialog
dialogButton2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {}
});
dialog.show();
}
android:fillViewport="true" in ScrollView solved my problem. Now its scrolling even inside dialog.
You can use simply below code on ScollView. it's working fine.
<ScrollView>
<LinearLayout android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
</LinearLayout>
</ScrollView>

Categories

Resources