用最簡單的方法去實現android中的一些提示

來源:互聯網
上載者:User

標籤:android

看個效果

一,載入框代碼

二,對話方塊代碼

三,提示框代碼













===============1

package com.idonoo.frame.widget;import android.app.ProgressDialog;import android.content.Context;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.TextView;import com.idonoo.frame.R;/** * 對比一下,使用黑色背景的還是蠻多的. * @author intbird * */public class ProgressDialogBar extends ProgressDialog {private String message;public ProgressDialogBar(Context context) {super(context, R.style.CustomDialog);}public ProgressDialogBar(Context context, String message) {super(context, R.style.CustomDialog);this.message = message;}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.custom_progress_dialog);}@Overridepublic void show() {show(message);}public void show(String message) {super.show();if (!TextUtils.isEmpty(message)) {TextView text = (TextView) findViewById(R.id.tv_message);text.setVisibility(View.VISIBLE);text.setText(message);}}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/linear_root"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@drawable/dialog_bg"    android:gravity="center"    android:minHeight="98dp"    android:minWidth="98dp"    android:orientation="horizontal" >    <ProgressBar        android:id="@+id/progress"        android:layout_width="56dp"        android:layout_height="56dp"        android:layout_gravity="center"        android:layout_margin="15dp"        android:indeterminateDrawable="@drawable/progress_dialog"        android:indeterminateDuration="1"        android:max="100"        android:progress="0" />    <TextView        android:id="@+id/tv_message"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginRight="30dp"        android:text=""        android:textColor="#FFFFFF"        android:textSize="18sp"        android:visibility="gone" /></LinearLayout>
============2

package com.idonoo.shareCar.widget;import com.idonoo.shareCar.R;import android.app.Dialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.os.Bundle;import android.text.TextUtils;import android.view.LayoutInflater;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.WindowManager.LayoutParams;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;/** * 對話方塊的樣式params需要注意; * @author intbird * */public class MyAlertDialog extends Dialog {private View view;private TextView tvTitle,tvContent;private EditText edContent;private Button btnYes,btnCacel;public enum  AlertStyle{ styleSingle,styleNoTitle,styleInput,styleTwoButton};private Context context;public MyAlertDialog(Context context) {super(context,android.R.style.Theme_Translucent_NoTitleBar);this.context = context;initView(R.layout.layout_alert_dialog);}private void initView(int layoutId){view= LayoutInflater.from(getContext()).inflate(layoutId, null);tvTitle=((TextView)view.findViewById(R.id.title));tvContent=((TextView)view.findViewById(R.id.content));edContent=(EditText)view.findViewById(R.id.ed_content);btnYes=(Button) view.findViewById(R.id.btn_yes);btnCacel=(Button) view.findViewById(R.id.btn_no);}public void initText(String title,String content) {tvTitle.setText(title);tvContent.setText(content);show();}public MyAlertDialog(Context context,AlertStyle style){this(context);switch (style) {case styleSingle:initView(R.layout.layout_alert_dialog_single);break;case styleNoTitle:initView(R.layout.layout_alert_dialog_notitle);break;case styleInput:initView(R.layout.layout_alert_dialog_input);break;case styleTwoButton:initView(R.layout.layout_alert_dialog);break;}}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(view);}public void setTextYes(String text){btnYes.setText(text);}public void setTextNo(String text){btnCacel.setText(text);}public EditText getEditText(){return edContent;}public void setEditText(EditText edContent){this.edContent=edContent;}@Overridepublic void show() {super.show();}public void show(String title,String content,View.OnClickListener yes){initText(title, content);btnYes.setOnClickListener(yes);}public void show(String title,String content,View.OnClickListener yes,View.OnClickListener cacel){initText(title, content);btnYes.setOnClickListener(yes);btnCacel.setOnClickListener(cacel);}public void show(String title,View.OnClickListener yes,View.OnClickListener cacel){tvTitle.setText(title);btnYes.setOnClickListener(yes);btnCacel.setOnClickListener(cacel);show();}@Overridepublic void dismiss() {super.dismiss();}@Overridepublic void cancel() {super.cancel();}public interface InputCallBack{public void inputCallBack(EditText edit);}}

=======3

    protected void showToast(int res){ //all fragments should be initUI();    <span style="white-space:pre"></span>String s=getResources().getString(res);    <span style="white-space:pre"></span>showToast(s);    }    protected void showToast(CharSequence s){        if (!TextUtils.isEmpty(s.toString())){        <span style="white-space:pre"></span>try{        <span style="white-space:pre"></span>if(toast!=null)        <span style="white-space:pre"></span>toast.cancel();        <span style="white-space:pre"></span>toast=new Toast(getActivity());        <span style="white-space:pre"></span>}catch(Exception ex){        <span style="white-space:pre"></span>toast=null;        <span style="white-space:pre"></span>}        <span style="white-space:pre"></span>        <span style="white-space:pre"></span>if(toast==null)        <span style="white-space:pre"></span>return ;        <span style="white-space:pre"></span>View view=getActivity().getLayoutInflater().inflate(R.layout.toasts, null);        <span style="white-space:pre"></span>TextView text=(TextView) view.findViewById(R.id.tv_toast);        <span style="white-space:pre"></span>text.setText(s.toString());        <span style="white-space:pre"></span>        <span style="white-space:pre"></span>toast.setView(view);        <span style="white-space:pre"></span>toast.setDuration(Toast.LENGTH_SHORT);        <span style="white-space:pre"></span>toast.show();        }    }




用最簡單的方法去實現android中的一些提示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.