在edittext android中错放了错误对话框

时间:2017-04-28 10:15:03

标签: android

我不知道这样解决:enter image description here

final Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.ic_error, getTheme());
d.setBounds(0, 0,
d.getIntrinsicWidth(), d.getIntrinsicHeight());
etRegisterFormEmail.setError(getString(R.string.email_not_valid), d);

如何解决错误信息?

2 个答案:

答案 0 :(得分:1)

etRegisterFormEmail.setError(“请填写有效表格”); - Prashant pattar

+1 +1 +1

答案 1 :(得分:0)

我会给你一个想法。 使用PopupView显示错误对话框并使用

    package pk;

    import java.util.Enumeration;

    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;

    import java.awt.BorderLayout;
    import java.awt.Font;

    import javax.swing.JTextArea;

    import java.awt.SystemColor;

    import javax.swing.JPanel;

    import java.awt.Color;

    import javax.swing.border.LineBorder;

    public class SIMessage extends JDialog implements ActionListener{
        private static final long serialVersionUID = 1L;
        public JButton oui=new JButton("Oui"),btnClose=new JButton(new ImageIcon("images\\logo\\delete.gif")),
        non=new JButton("Non"),annuler=new JButton("Annuler"),ok=new JButton("OK"); 
        public JLabel lblImgErr=new JLabel(new ImageIcon("images\\logo\\msgErreur.png")),
                lblImgConf=new JLabel(new ImageIcon("images\\logo\\msgQuestion.png")),
                lblImgWarning=new JLabel(new ImageIcon("images\\logo\\msgWarning.png")),
                lblImgInfo=new JLabel(new ImageIcon("images\\logo\\msgInformation.png")),
                lblImgQuestion=new JLabel(new ImageIcon("images\\logo\\msgQuestion.png")),
                lblImgIconApp=new JLabel(new ImageIcon("images\\logo\\clntIco.ico"));
        public JLabel title=new JLabel(),message=new JLabel();

        public enum TypeMessage{
            ERROR_MESSAGE,
            CONFIRMATION_MESSAGE,
            WARNING_MESSAGE,
            INFORMATION_MESSAGE,
            VALIDATION_MESSAGE
        }
        public SIMessage(JFrame parent,String title,TypeMessage type,String message) {
                 super(parent,true);
            setUndecorated(true); 
            getContentPane().setLayout(new GridLayout(1, 1));

                JPanel mainDgPanel = new JPanel();
                mainDgPanel.setBorder(new LineBorder(new Color(255, 255, 255), 3, true));
                mainDgPanel.setBounds(0, 0, 444, 156);
                getContentPane().add(mainDgPanel);
                mainDgPanel.setLayout(null);
                mainDgPanel.setBackground(Color.decode(EcranPrincipal.blueThemeCP));

                JTextArea txtrTextarea = new JTextArea(message);
                txtrTextarea.setRows(2);
                txtrTextarea.setBounds(123, 62, 340, 80);
                txtrTextarea.setFont(new Font("Iskoola Pota", Font.PLAIN, 18));
                txtrTextarea.setEditable(false);
                txtrTextarea.setFocusable(false);
                txtrTextarea.setOpaque(false);
                txtrTextarea.setBorder(null);
                txtrTextarea.setWrapStyleWord(true);
                txtrTextarea.setLineWrap(true);
                txtrTextarea.setForeground(Color.decode(EcranPrincipal.blueThemeBT));
                mainDgPanel.add(txtrTextarea);

                JPanel panelButtons = new JPanel();
                panelButtons.setBounds(47, 115, 344, 30);
                mainDgPanel.add(panelButtons);

                switch(type)
                {
                case ERROR_MESSAGE:
                    {
                        JLabel lblNewLabel =lblImgErr;
                        lblNewLabel.setBounds(10, 69, 79, 14);
                        mainDgPanel.add(lblNewLabel);

                        JButton btnOk = ok;
                        panelButtons.add(btnOk);
                    break;
                    }
                case CONFIRMATION_MESSAGE:
                    {
                         JLabel lblNewLabel =lblImgConf;
                            lblNewLabel.setBounds(10, 69, 79, 14);
                            mainDgPanel.add(lblNewLabel);

                            JButton btnOui = oui;
                            panelButtons.add(btnOui);
                    break;
                    }
                case WARNING_MESSAGE:
                    {
                         JLabel lblNewLabel =lblImgWarning;
                            lblNewLabel.setBounds(10, 69, 79, 14);
                            mainDgPanel.add(lblNewLabel);

                            JButton btnOk = ok;
                            panelButtons.add(btnOk);
                    break;
                    }
                case INFORMATION_MESSAGE:
                    {
                         JLabel lblNewLabel =lblImgInfo;
                            lblNewLabel.setBounds(10, 69, 79, 14);
                            mainDgPanel.add(lblNewLabel);

                            JButton btnOk = ok;
                            panelButtons.add(btnOk);
                    break;
                    }
                case VALIDATION_MESSAGE:
                    {
                         JLabel lblNewLabel =lblImgConf;
                            lblNewLabel.setBounds(10, 69, 79, 14);
                            mainDgPanel.add(lblNewLabel);


                            JButton btnOui = oui;
                            panelButtons.add(btnOui);

                            JButton btnNon = non;
                            panelButtons.add(btnNon);

                            JButton btnAnnuler = annuler;
                            panelButtons.add(btnAnnuler);

                    break;
                    }
                    default:
                }
                ok.addActionListener(this);
                oui.addActionListener(this);

                JPanel panel = new JPanel();
                panel.setBounds(0, 0, 444, 27);
                mainDgPanel.add(panel);
                panel.setBackground(Color.WHITE);
                panel.setLayout(null);

                JButton btnCloseDf = btnClose;
                btnCloseDf.setBounds(411, 0, 39, 23);
                panel.add(btnCloseDf);

                JLabel lblIconApp =lblImgIconApp;
                lblIconApp.setBounds(10, 4, 77, 14);
                panel.add(lblIconApp);

                JLabel lblTitle = new JLabel(title);
                lblTitle.setBounds(190, 4, 46, 14);
                panel.add(lblTitle);
                this.pack();
                this.setVisible(true);
        }
public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        Object source=e.getSource();
        if(source==oui||source==ok)
        {
            this.dispose();
        }
    }

,弹出窗口将显示在View v。

上方