ارسال پاسخ 
 
امتیاز موضوع:
  • 1 رأی - میانگین امتیازات: 5
  • 1
  • 2
  • 3
  • 4
  • 5
ایجاد صفحه popup در برنامه نویسی اندروید استدیو
10-01-2018, 06:34 PM
ارسال: #1
ایجاد صفحه popup در برنامه نویسی اندروید استدیو
در ابتدا یک Layout جدید با هر عنوانی ایجاد می کنیم.

کد:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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_gravity="right"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textm1001"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        android:textColor="@color/colorAccent"
        android:textSize="100px"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="64dp"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textm1001"
        app:layout_constraintVertical_bias="0.0"
        tools:layout_editor_absoluteX="236dp" />
</android.support.constraint.ConstraintLayout>

سپس کد زیر را در Layout اصلی می نویسیم و در هنگام اجرا این Layout دومی به صورت صفحه popup نمایش داده می شود:

کد:
package com.example.dial.dial;

import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        UDF_ShoDial();
    }


    protected void UDF_ShoDial()
    {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            View mView = getLayoutInflater().inflate(R.layout.dial_main2 , null);
            TextView textView = (TextView)mView.findViewById(R.id.textm1001);
            textView.setText("پیام قابل نمایش . . .");
            builder.setView(mView);
            AlertDialog dialog = builder.create();
            dialog.show();
        } catch (Exception e) {
            TextView textView3 = (TextView)findViewById(R.id.pptr);
            textView3.setText(e.getMessage().toString());
        }
    }
}

و کد XML مربوط به Layout اصلی به صورت زیر می باشد:

کد:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">

    <TextView

        android:id="@+id/pptr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>


==================================================
طراحی وب سایت
پروژه های برنامه نویسی تجاری
دانلود پروژه های ASP.NET وب سایتهای آماده به همراه توضیحات
دانلود پروژه های سی شارپ و پایگاه داده SQL Server همراه توضیحات و مستندات
دانلود پروژه های UML نمودار Usecase نمودار class نمودرا activity نمودار state chart نمودار DFD و . . .
دانلود پروژه های حرفه ای پایگاه داده SQL Server به همراه مستندات و توضیحات
پروژه های حرفه ای پایگاه داده Microsoft access به همراه مستندات و توضیحات
دانلود پروژه های کارآفرینی
دانلود گزارشهای کارآموزی کارورزی تمامی رشته های دانشگاهی
قالب تمپلیت های آماده وب سایت ASP.NET به همراه Master page و دیتابیس
برنامه های ایجاد گالری عکس آنلاین با ASP.NET و JQuery و اسلایدشو به همراه کد و دیتابیس SQL کاملا Open Source واکنشگرا و ساده به همراه پایگاه داده
==================================================
یافتن تمامی ارسال‌های این کاربر
نقل قول این ارسال در یک پاسخ
ارسال پاسخ 


پرش به انجمن:


کاربرانِ درحال بازدید از این موضوع: 1 مهمان