• android 自己定义Dialog去除黑色边框


    在自己定义Dialog时显示的界面中老是有黑色的边框,以下就介绍使用style去除黑色边框方法。


    首先在values/styles定义自己定义样式:

      <style name="MyDialog" parent="@android:Theme.Dialog">
            <item name="android:windowFrame">@null</item>
            <item name="android:windowBackground">@drawable/actionbar_item_background</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:background">#FFF</item>
        </style>
    <item name="android:windowBackground">@drawable/actionbar_item_background</item>这个是重点,仅仅有加入了这个后才干去除黑色的边框


    或者是自己定义一个透明的背景图片。这样也能够去除黑色边框!

    代码:

    	static class MsgDialog extends Dialog implements
    			android.view.View.OnClickListener {
    		private String text;
    
    
    		public MsgDialog(Context context, String text) {
    			super(context, R.style.MyDialog);
    			this.text = text;
    		}
    
    
    		@Override
    		protected void onCreate(Bundle savedInstanceState) {
    			super.onCreate(savedInstanceState);
    			setContentView(R.layout.login_dialog);
    			TextView txt = (TextView) findViewById(R.id.login_dialog_txt);
    			txt.setText(text);
    			TextView confirm = (TextView) findViewById(R.id.login_dialog_btn);
    			confirm.setOnClickListener(this);
    		}
    
    
    		@Override
    		public void onClick(View v) {
    			MsgDialog.this.dismiss();
    		}
    
    
    	}



    xml:

    <?xml version="1.0" encoding="utf-8"?

    > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" android:background="#FFF" android:orientation="vertical" > <TextView android:id="@+id/login_dialog_txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="TextView" android:textColor="@color/grey3" android:textSize="18sp" /> <!-- 切割线 --> <View android:id="@+id/view_division" style="@style/Viewborder" /> <TextView android:id="@+id/login_dialog_btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:height="50dp" android:text="确定" android:textColor="@color/grey3" android:textSize="20sp" /> </LinearLayout>



    --------------------------------------------------------------------------华丽丽的切割线-------------------------------------------------------------------------

    dialog自己定义动画:

    1、在style.xml中加入

        <style name="AA" parent="@android:style/Theme.Holo.Light.Dialog">
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowIsTranslucent">false</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowFullscreen">false</item>
            <item name="android:windowBackground">@android:color/transparent</item>
            <item name="android:windowAnimationStyle">@style/dialogWindowAnim</item>
            <item name="android:backgroundDimEnabled">true</item>
            <item name="android:backgroundDimAmount">0.4</item>
        </style>
    
        <style name="dialogWindowAnim">
            <item name="android:windowEnterAnimation">@anim/enter</item>
            <item name="android:windowExitAnimation">@anim/exit</item>
        </style>
    
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:fromXScale="100%"
        android:fromYScale="100%"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="50%"
        android:toYScale="50%" >
    
    </scale>


    2、anim/enter.xml

    <scale
            android:fromXScale="50%"
            android:fromYScale="50%"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="100%"
            android:toYScale="100%" >
        </scale>
    

      anim/exit.xml

    3、在代码中

    在DialogFragment的方法onCreateDialog中使用

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
    				R.style.AA);

    dialg自己定义动画,ok


  • 相关阅读:
    模块(module)
    编译和解释性语言和python运行方式
    管道通信初级
    Page.TryUpdateModel 方法
    运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)
    HttpResponse 类
    ASP.NET中IsPostBack详解
    3.4.1 使用过滤式扩展方法(P43-44)
    使用扩展方法(Chapter3 P39-41)
    C#对象初始或器-Chapter3 P38
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6747486.html
Copyright © 2020-2023  润新知