2015-11-02 3 views
1

Я использовал диалоговое окно cutsom в моем MainActivity для всплывающего экрана. Я добавил крест-кнопку, чтобы закрыть всплывающее окно . здесь, в моем коде, эта кросс-кнопка показывает внутри всплывающее окно. Теперь я хочу, чтобы он показывался на границе всплывающего окна. пожалуйста, помогите мне получить это ..Как получить крест-кнопку/изображение в пользовательском диалоговом окне границы

Ниже моя code..any помощь будет оценена ... заранее спасибо ..

Java Файл

HomePage.java

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.app.Dialog; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.Point; 
import android.os.Bundle; 
import android.view.Display; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.support.v4.app.DialogFragment; 

public class HomePage extends Activity { 

final Context context = this; 

Button b1; 
Button b2; 

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home_page); 

    b1 = (Button) findViewById(R.id.button6); 
    b2 = (Button) findViewById(R.id.button7); 
    b2.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(HomePage.this,RegisterPage.class); 
      startActivity(intent); 
     } 

    }); 

    b1.setOnClickListener(new OnClickListener() { 

     @SuppressLint("NewApi") 
    @Override 
     public void onClick(View arg0) { 

     // custom dialog 
    final Dialog dialog = new Dialog(context); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.activity_login_page); 

     WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
     Display display = wm.getDefaultDisplay(); // getting the screen size of device 
     Point size = new Point(); 
     display.getSize(size); 
     int width = size.x - 20; // Set your heights 
     int height = size.y - 80; // set your widths 

     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     lp.copyFrom(dialog.getWindow().getAttributes()); 

     lp.width = width; 
     lp.height = height; 

     dialog.getWindow().setAttributes(lp); 
     dialog.show(); 


     ImageView image = (ImageView) dialog.findViewById(R.id.cancel_btn); 
     image.setImageResource(R.drawable.cancel2); 
     image.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       dialog.dismiss(); 
      } 

     }); 
    Button dialogButton = (Button) dialog.findViewById(R.id.button1); 
    dialogButton.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
     //dialog.dismiss(); 
     Intent intent = new Intent(HomePage.this,CategoryPage.class); 
     startActivity(intent); 
      } 
    }); 

     dialog.show(); 
     } 
    }); 

} 
} 

XML File

activity_home_page.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#fff" 

tools:context=".MainActivity" > 

<LinearLayout android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#fff" 
     android:paddingLeft="0dp" 
     android:paddingRight="0dp" 
     android:paddingTop="5dip" 
     android:paddingBottom="5dip"> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginTop="0dp" 
    android:src="@drawable/miiskylogo" /> 

</LinearLayout> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/header" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="163dp" 
    android:orientation="vertical" 
    android:paddingBottom="0dp" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" > 


    <Button 
      android:id="@+id/button6" 
      android:layout_width="230dp" 
      android:layout_height="50dp" 
      android:background="#00b0ff" 
      android:layout_weight="0.1666" 
      android:textSize="18dp" 
      android:textColor="#fff" 
      android:paddingLeft="3dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="32dp" 
      android:drawableLeft="@drawable/lock" 
      android:text="Login with SVAPP" /> 

    <Button 
      android:id="@+id/button7" 
      android:layout_width="230dp" 
      android:layout_height="50dp" 
      android:background="#00b0ff" 
      android:layout_weight="0.1666" 
      android:textSize="18dp" 
      android:textColor="#fff" 
      android:paddingLeft="3dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="15dp" 
      android:drawableLeft="@drawable/regis" 
      android:text="Register with SVAPP" /> 
</LinearLayout> 

</ScrollView> 
</RelativeLayout> 

activity_login_page.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

android:background="#fff" 
tools:context="com.example.miiskyproject.Login" > 

<ImageView 
android:id="@+id/cancel_btn" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentRight="true" 
android:layout_alignParentTop="true" 
android:src="@drawable/cancel2" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="130dp" 
    android:layout_height="90dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="34dp" 
    android:src="@drawable/miiskylogo" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="80dp" 
     android:layout_height="35dp" 
     android:layout_marginTop="190dp" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="10dp" 
     android:background="@drawable/loginedit" 
     android:ems="6" 
     android:hint="User Name" 
     android:padding="8dp" 
     android:textColor="#000" 
     android:textStyle="bold" 
     android:textColorHint="#bdbdbd" 
     android:textSize="13dp" > 

     <requestFocus /> 
    </EditText> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="80dp" 
     android:layout_height="35dp" 
     android:layout_marginTop="190dp" 
     android:layout_marginRight="15dp" 
     android:background="@drawable/loginedit" 
     android:ems="6" 
     android:hint="Password" 
     android:inputType="textPassword" 
     android:padding="8dp" 
     android:textColor="#000" 
     android:textStyle="bold" 
     android:textColorHint="#bdbdbd" 
     android:textSize="13dp" /> 



    <Button 
     android:id="@+id/button1" 
     android:layout_width="70dp" 
     android:layout_height="35dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="190dp" 
     android:background="@drawable/loginbutton" 
     android:ems="7" 
     android:text="Login" 
     android:textColor="#fff" 
     android:textSize="12dp" /> 



</LinearLayout> 
<LinearLayout 
    android:id="@+id/panelInsurance7" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="15dp" 
    android:layout_marginTop="10dp" 
    > 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="225dp" 
     android:text="Forget Your Password?" 

     android:textSize="13dp" 
     android:textStyle="bold" /> 

    </LinearLayout> 

<LinearLayout 
    android:id="@+id/linear1" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="15dp" 
    android:layout_marginTop="10dp"> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="250dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="280dp" 
     android:padding="10dp" 
     android:layout_marginRight="20dp" 
     android:text="Lorem Ipsum dolor sit amet," 
     android:background="@drawable/loginedit" 
     android:textSize="18dp" 
     android:textStyle="bold" /> 

    </LinearLayout> 

</RelativeLayout> 

Я хочу перекрестную кнопку нечто похожее на изображение ниже. Click Here

+0

Возможный дубликат [пользовательский диалог с кнопкой закрытия] (http://stackoverflow.com/questions/20258730/custom-dialog-with-close-button) – camelCaseCoder

+0

Вы не определили относительное положение linearlayout ниже изображения в файле activity_login_page .xml – bond007

+0

@ camelcasecoder..even, я сталкиваюсь с той же проблемой..dint получил решение еще .. thatats сообщение здесь. –

ответ

0

Попробуйте это решение:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#fff" 
     tools:context="com.example.miiskyproject.Login" > 

    <LinearLayout 
     android:id="@+id/cancel_layuot" 
     android:layout_width="match_parent" 
     android:gravity="right" 
     android:background="@android:color/transparent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/cancel_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="130dp" 
     android:layout_height="90dp" 
     android:layout_below="@+id/cancel_layuot" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="34dp" 
     android:src="@drawable/left_arrow" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/cancel_layuot" > 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="80dp" 
      android:layout_height="35dp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="190dp" 
      android:background="@drawable/ic_launcher" 
      android:ems="6" 
      android:hint="User Name" 
      android:padding="8dp" 
      android:textColor="#000" 
      android:textColorHint="#bdbdbd" 
      android:textSize="13dp" 
      android:textStyle="bold" > 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="80dp" 
      android:layout_height="35dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="190dp" 
      android:background="@drawable/ic_launcher" 
      android:ems="6" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:padding="8dp" 
      android:textColor="#000" 
      android:textColorHint="#bdbdbd" 
      android:textSize="13dp" 
      android:textStyle="bold" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="70dp" 
      android:layout_height="35dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="190dp" 
      android:background="@drawable/ic_launcher" 
      android:ems="7" 
      android:text="Login" 
      android:textColor="#fff" 
      android:textSize="12dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/panelInsurance7" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="10dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="225dp" 
      android:text="Forget Your Password?" 
      android:textSize="13dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linear1" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/cancel_layuot" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="10dp" > 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="280dp" 
      android:background="@drawable/ic_launcher" 
      android:padding="10dp" 
      android:text="Lorem Ipsum dolor sit amet," 
      android:textSize="18dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

</RelativeLayout> 

Вы увидите что-то вроде этого:

enter image description here

Просто заменить изображения ic_launcher с присвоенными изображениями.

+0

нет его не работает .. он показывает внутри себя. –

+0

проверить измененный ответ. – activesince93

+0

в эмуляторе, даже я получаю как этот вид ... но когда я запускаю свое физическое устройство, оно отображается только внутри. Но мне нужно что-то изменить в моей HomePage.java ..? –

Смежные вопросы