一、布局文件
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal"> android:id="@+id/iin" android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:background="@drawable/yunajiao" android:gravity="center"> android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="消息提示" android:textColor="@color/yellow" /> android:id="@+id/iin2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@+id/iin" android:background="@color/colorAccent"> android:id="@+id/text23" android:layout_width="match_parent" android:layout_height="1dp" /> android:id="@+id/iin3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/iin2" android:gravity="center" android:background="@drawable/background"> android:id="@+id/text2e" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="网络异常,请检查网络!" android:layout_marginBottom="25dp"/> android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> android:id="@+id/text24e" android:layout_width="match_parent" android:layout_height="40dp" android:layout_weight="1" android:background="@drawable/slec1t" android:clickable="true" android:gravity="center" android:text="确定" /> android:id="@+id/text444" android:layout_width="match_parent" android:layout_height="40dp" android:layout_weight="1" android:background="@drawable/slect" android:clickable="true" android:gravity="center" android:text="取消" />
二,选择器
1最上面选择器,左右圆角
xml version="1.0" encoding="utf-8"?>三,中间选择器,底部圆角xmlns:android="http://schemas.android.com/apk/res/android"> android:color="@color/dark_brown"> android:topRightRadius="10dp" android:topLeftRadius="10dp">
xml version="1.0" encoding="utf-8"?>四,确定和取消选择器xmlns:android="http://schemas.android.com/apk/res/android"> android:color="@color/white"> android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp">
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"> - android:state_pressed="true">
android:color="@color/colorPrimary"> android:bottomLeftRadius="10dp"> - android:state_pressed="false">
android:color="@color/dark_gray"> android:bottomLeftRadius="10dp">
五代码如下
package guy.cldvision.com.fragmentdialog; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.animation.AlphaAnimation; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; /** * 出货提示页面 * Created by zero on 2016/6/12. */ public class ShipWarnFragment extends DialogFragment implements View.OnClickListener{ private TextView txtUserName; private TextView txtCoffeeName; private ImageView imaBackGround; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.fragment, null); initView(layout); // loadDetail(); txtCoffeeName= (TextView) layout.findViewById(R.id.text24e); txtUserName=(TextView) layout.findViewById(R.id.text444); txtCoffeeName.setOnClickListener(this); txtUserName.setOnClickListener(this); return layout; } public void onClick(View v){ switch (v.getId()){ case R.id.text24e : Toast.makeText(getActivity(),"点击确定",Toast.LENGTH_LONG).show(); dismiss(); break; case R.id.text444 : Toast.makeText(getActivity(),"点击取消",Toast.LENGTH_LONG).show(); dismiss(); break; } } // /** // * 加载详情 // */ // private void loadDetail() { // //获取数据 // // // //背景透明度渐变动画 // AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); // alphaAnimation.setDuration(5000); // alphaAnimation.setFillAfter(true); // alphaAnimation.setRepeatCount(20); // imaBackGround.startAnimation(alphaAnimation); // } /** * 初始化控件 * * @param layout */ private void initView(View layout) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题 } @Override public void onStart() { super.onStart(); //设置该dialogFragment的背景为透明 getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置该dialogFragment全屏 getDialog().getWindow().setLayout(600,400); } }
六 点击显示
package guy.cldvision.com.fragmentdialog; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; /** * Created by Administrator on 2016/12/21. */ public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void btn(View v){ setContentView(R.layout.activity_main); ShipWarnFragment shipWarnFragment=new ShipWarnFragment(); shipWarnFragment.show(getSupportFragmentManager(),""); shipWarnFragment.setCancelable(false); } }
最后效果图如下: