編輯:關於Android編程
效果圖:
main_activity.xml
MainActivity.java:
package com.example.mydialog;
import android.app.Activity;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import dialog.MessageFragment;
public class MainActivity extends ActionBarActivity {
//提示框fragment
private MessageFragment mMessageFragment;
//bundle用來傳遞提示框的信息
private Bundle bundle;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showdialog();
}
});
}
private void showdialog() {
if (mMessageFragment == null) {
mMessageFragment = new MessageFragment();
}
if (bundle == null) {
bundle = new Bundle();
}
bundle.putString(content, 是否確認收件);
bundle.putString(title, 標題);
mMessageFragment.setOnResultListener(new OnItemMsgResultListener());
mMessageFragment.setArguments(bundle);
// 顯示提示窗口
mMessageFragment.show(getFragmentManager(), );
}
class OnItemMsgResultListener implements MessageFragment.OnMsgResultListener {
public OnItemMsgResultListener() {
}
@Override
public void onResultFun(int resultCode) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(MainActivity.this,確認,Toast.LENGTH_SHORT).show();
// getAliasData();
}else{
Toast.makeText(MainActivity.this,取消,Toast.LENGTH_SHORT).show();
}
}
}
}
message_dialog.xml:
button_msg_cancel.xml:
-
-
-
button_msg_submit.xml:
-
-
-
MessageFragment.java:
package dialog;
import android.app.Activity;
import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import com.example.mydialog.R;
public class MessageFragment extends DialogFragment {
public static final String TAG = MessageDialog;
private OnMsgResultListener mOnMsgResultListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//message_dialog是提示框的布局
View show_view = inflater.inflate(R.layout.message_dialog, null);
TextView mTxtContent = (TextView) show_view.findViewById(R.id.tv_content);
TextView mTxtTitle = (TextView) show_view.findViewById(R.id.tv_title);
Button btnSubmit = (Button) show_view.findViewById(R.id.btn_submit);
Button btnCancel = (Button) show_view.findViewById(R.id.btn_cancel);
Bundle bundle = this.getArguments();
if(bundle != null){
String title = bundle.getString(title);
if(title!=null){
mTxtTitle.setText(bundle.getString(title));
}
mTxtContent.setText(bundle.getString(content));
}
btnSubmit.setOnClickListener(btnClickListener);
btnCancel.setOnClickListener(btnClickListener);
setCancelable(false);
return show_view;
}
public void setOnResultListener(OnMsgResultListener listener) {
mOnMsgResultListener = listener;
}
View.OnClickListener btnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_submit:
mOnMsgResultListener.onResultFun(Activity.RESULT_OK);
dismiss();
break;
case R.id.btn_cancel:
mOnMsgResultListener.onResultFun(Activity.RESULT_CANCELED);
dismiss();
break;
default:
break;
}
}
};
public interface OnMsgResultListener {
void onResultFun(int resultCode);
}
}
ViewRoot和DecorViewViewRoot對應於ViewRootImpl類,是連接WindowManager和DecorView的紐帶,View的三大流程均是通
ViewAnimator可以實現帶動畫效果的View切換,其派生的子類是一些帶動畫效果切換功能的組件。ViewAnimator支持的XML屬性: Attribute
UI編程通常都會伴隨事件處理,Android也不例外,它提供了兩種方式的事件處理:基於回調的事件處理和基於監聽器的事件處理。對於基於監聽器的事件處理而言,主要就是為And
趁著周一休息,更新一下博客。最近項目中使用到了分組管理,需要實現Listview的Item拖動處理。查略一下資料和借鑒了別人的代碼將功能實現了。現在整理一下代碼,方便自己