Blog purpose for android basic example for android app developer. any query please my contact

Tuesday 2 February 2021

android studio popup window with input text

 android studio popup window with input text

In this Article Today Learn android studio popup window with input text. follow the full source code android studio popup window with input text.


1.MainActivity.java:

package com.akash.popupwindow;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.text.InputType;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;


public class MainActivity extends AppCompatActivity {

    private String m_Text = "";

    Button btnview;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        btnview=(Button)findViewById(R.id.btnview);

        btnview.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

                builder.setTitle("Title");


// Set up the input

                final EditText input = new EditText(MainActivity.this);

// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text

                input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

                builder.setView(input);


// Set up the buttons

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    @Override

                    public void onClick(DialogInterface dialog, int which) {

                        m_Text = input.getText().toString();

                    }

                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                    @Override

                    public void onClick(DialogInterface dialog, int which) {

                        dialog.cancel();

                    }

                });


                builder.show();

            }

        });

    }

}



2.activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"

    tools:context=".MainActivity">


    <Button

        android:id="@+id/btnview"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Click open popup"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintLeft_toLeftOf="parent"

        app:layout_constraintRight_toRightOf="parent"

        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>


3.AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.akash.popupwindow">


    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>


</manifest>


4.colors.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <color name="colorPrimary">#6200EE</color>

    <color name="colorPrimaryDark">#3700B3</color>

    <color name="colorAccent">#03DAC5</color>

</resources>


5.strings.xml:

<resources>

    <string name="app_name">Popup window</string>

</resources>


6.styles.xml:

<resources>

    <!-- Base application theme. -->

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <item name="colorAccent">@color/colorAccent</item>

    </style>


</resources>


7.Output:

android studio popup window with input text













android studio popup window with input text


10 comments:

  1. It is a great post really enjoy reading such type of articles. I will also recommend you to visit Alightmotionguru.com, a blog related to AM app a great app having multiple motion effects
    . You can easily download such effects.

    ReplyDelete
  2. Interesting post with the points that I was missing. If you are interested in making cool videos get Alight motion for ios

    ReplyDelete
  3. I love reading things like this, so thank you for writing it. A excellent video editor with a variety of motion effects is the Alight Motion video editor, and I highly recommend it. Such effects are readily available for download at https://alightmotionapps.com/alight-motion-effects/

    ReplyDelete
  4. Idle Office Tycoon Mod APK This article is very impressive and this knowledge is really interesting. If you want to know more about this game visit website.

    ReplyDelete
  5. This article will guide you how to Mask On Alight Motion free of cost

    ReplyDelete
  6. A Pressure Conversion Calculator is a tool used to convert pressure measurements between different units such as atmospheres, pascals, pounds per square inch (psi), and others. Users input the value they want to convert and select the units they're converting from and to. It simplifies calculations in engineering, meteorology, and fluid mechanics, ensuring accurate pressure measurements across different systems. Click here to get this tool

    ReplyDelete