Android - 如何使用底部的小模糊文本创建此警报对话框?

时间:2015-12-24 06:06:30

标签: android dialog android-alertdialog

我想制作一个底部有点模糊的文字对话框。below is dialog

1 个答案:

答案 0 :(得分:1)

我已添加上述对话框的代码

MainActivity.java

package com.example.balaji.myapplication;

import android.app.Dialog;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        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) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        // custom dialog
        // custom dialog
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.custom);
        dialog.setTitle("Title...");

        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("abcdefghijklmnopqrstuvwxyz \\n abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvvvabcdefghijklmnopqrstuvwxyzvvvvvvvvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvvvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzvabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");


        dialog.show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, 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);
    }
}

custom.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:scrollbars="vertical"

    android:background="@android:color/white"
    android:layout_height="200dp" >

    <TextView
        android:id="@+id/text"
        android:scrollbars="vertical"
        android:textColor="@android:color/black"
        android:textSize="15dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />


    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:background="@drawable/gradient"></LinearLayout>


</RelativeLayout>

gradient.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <gradient
        android:startColor="#55ffffff"
        android:endColor="#eeffffff"
        android:angle="270" />
</shape>

最终输出将如下所示

enter image description here