个人笔记(第五篇)(Dialog的完整写法)

啊。过了节之后就是懒懒的,没动手写过了,其实是有点忙了。

总结一下这些天的问题吧;

第一个:如何在Adapter中进行点击事件以及数据的删除,以及在适配器中进行界面跳转动作(原因在这里http://blog.csdn.net/scwhy/article/details/6650712 ,解决方法很简单,添加一行代码就行了)

listItemView.button2.setOnClickListener(new View.OnClickListener() {
    @Override
    public
    void onClick(View v) {
        Toast.makeText(context, "被点击了", Toast.LENGTH_LONG).show();
        Intent intent=new Intent(context,ShouhuoActivity.class);
        intent.putExtra("position",position);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);这一行很重要
        context.startActivity(intent);
    }
});
listItemView.button3.setOnClickListener(new View.OnClickListener() {
    @Override
    public
    void onClick(View v) {
        Toast.makeText(context, "被点击了", Toast.LENGTH_LONG).show();
        listitems.remove(position);
        notifyDataSetChanged();
    }
});
第二个;Dialog页面的圆角问题:

一定要注意你的控件是否覆盖到了你的圆角,如果覆盖到了你的圆角,是不会显示出圆角效果的,应该把此控件也设置为圆角才行

圆角的写法,在drawable文件夹中新建文件,名字随意。对应的分别控制四个边角。数值越大,圆角越大

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <solid android:color="#ffffff" />
                <corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
                         android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" />
                <stroke android:width="0dp" android:color="@color/blue" />
            </shape>
        </item>
    </layer-list>
对应的style,在2.3版本需要继承的是
@style/Theme.AppCompat.Dialog

然后如下写就行

<style name="TranslucentTheme" parent="@style/Theme.AppCompat.Dialog">
    <!-- 边框 -->
    <item name="android:windowFrame">@null</item>
    <!-- 是否浮现在activity之上 -->
    <item name="android:windowIsFloating">true</item>
    <!-- 半透明 -->
    <item name="android:windowIsTranslucent">true</item>
    <!-- 无标题 -->
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@android:color/transparent</item>
    <!-- 背景透明 -->
    <item name="android:windowBackground">@android:color/transparent</item>
    <!-- 模糊 -->
    <item name="android:backgroundDimEnabled">true</item>
    <!-- 遮罩层 -->
    <item name="android:backgroundDimAmount">0.5</item>
</style>
自定义的MyDialog:

public class MyDialog extends Dialog{
    private static int mTheme = R.style.TranslucentTheme;
    private List<Map<String,Object>> listItems;
    private TrackListViewAdapter trackListViewAdapter;
    private ListView listView;
    private Context mContext;


    public MyDialog(Context context, int theme) {
        super(context, theme);
        this.mContext = context;
    }

    public MyDialog(Context context) {
        super(context, mTheme);
        this.mContext = context;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_track);
        initView();
        listItems=initItmes();
        trackListViewAdapter=new TrackListViewAdapter(getContext(),listItems);
        listView.setAdapter(trackListViewAdapter);


    }
    public void initView(){
        listView=(ListView)findViewById(R.id.person_track_listview);

    }
    private List<Map<String,Object>> initItmes( ){
        listItems=new ArrayList<Map<String,Object>>();
        Map map1=new HashMap();
        map1.put("bool",true);
        map1.put("time","18:06");
        map1.put("dizhi","【收货地址】河南省郑州市中原区 中原西路街道 河南省郑州市中原区中路万达A座1938");
        Map map2=new HashMap();
        map2.put("bool",false);
        map2.put("time","12:06");
        map2.put("dizhi","已发出");
        Map map3=new HashMap();
        map3.put("bool",false);
        map3.put("time","6:06");
        map3.put("dizhi","已发出");
        listItems.add(map1);
        listItems.add(map2);
        listItems.add(map3);
        return listItems;
    }
}
使用方法就是在你需要的地方加上两句话

Dialog dialog=new MyDialog(getContext());
dialog.show();
第三个;彩带条的写法:

网上找来的。我就直接贴代码了。直接复制就能用:

首先,在values添加文件attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ColourLineView">
        <!--线条高度-->
        <attr name="line_height" format="dimension"/>
        <!--第一种颜色块的宽度-->
        <attr name="item_width" format="dimension"/>
        <!--第二种颜色块的宽度-->
        <attr name="separation_width" format="dimension"/>
        <!--平行四边形倾斜的程度-->
        <attr name="lean_degree" format="dimension"/>
        <!--第一种颜色-->
        <attr name="first_color" format="color"/>
        <!--第二种颜色-->
        <attr name="second_color" format="color"/>
        <!--线条底色-->
        <attr name="canvas_color" format="color"/>
    </declare-styleable>
</resources>

然后是自定义的View:

/**彩色分割线
 * Created by Administrator on 2017/5/31 0031.
 */

public class ColourLineView extends View {

    //线条高度
    private float line_height;
    //每个颜色块的宽度
    private float item_width;
    //每两个颜色快之间的间距
    private float separation_width;
    //平行四边形倾斜的程度
    private float lean_degree;
    //第一种颜色块的颜色
    private int first_color;
    //第二种颜色块的颜色
    private int second_color;
    //线条底色
    private int canvas_color;

    public ColourLineView(Context context) {
        super(context, null);
    }

    public ColourLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initAttr(context, attrs);
    }

    public ColourLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initAttr(context, attrs);
    }

    public void initAttr(Context context, AttributeSet attrs){
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColourLineView);
        line_height = typedArray.getDimension(R.styleable.ColourLineView_line_height, 20);
        item_width = typedArray.getDimension(R.styleable.ColourLineView_item_width, 20);
        separation_width = typedArray.getDimension(R.styleable.ColourLineView_separation_width, 20);
        lean_degree = typedArray.getDimension(R.styleable.ColourLineView_lean_degree, 5);
        first_color = typedArray.getColor(R.styleable.ColourLineView_first_color, Color.RED);
        second_color = typedArray.getColor(R.styleable.ColourLineView_second_color, Color.GREEN);
        canvas_color = typedArray.getColor(R.styleable.ColourLineView_canvas_color, Color.WHITE);
        typedArray.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Path path = new Path();
        int lineWidth = getWidth();
        int lineHeight = getHeight();
        int count = (item_width + separation_width == 0) ? 0 : lineWidth / (int) (item_width + separation_width) + 1;
        for(int i=0; i < count; i++){
            canvas.save();
            path.reset();//重置路径
            path.moveTo(lean_degree + (item_width + separation_width) * i, 0);//左上点
            path.lineTo((item_width + separation_width) * i, lineHeight);//左下点
            path.lineTo(item_width * (i + 1) + separation_width * i, lineHeight);//右下点
            path.lineTo(lean_degree + item_width * (i + 1) + separation_width * i, 0);//右上点
            canvas.clipPath(path);//截取路径所绘制的图形
            if(i % 2 == 0){
                canvas.drawColor(first_color);
            }else{
                canvas.drawColor(second_color);
            }
            canvas.restore();
        }
    }
}
最后在布局里面需要添加的地方加入:颜色和宽度就自己调整吧,代码很详细了

<com.example.administrator.qinghuayuan.untils.ColourLineView
    android:layout_width="match_parent"
    android:layout_height="@dimen/DIMEN_5PX"
    android:background="#fff"
    app:first_color="@color/juhong"
    app:second_color="@color/blue"
    app:item_width="@dimen/DIMEN_15PX"
    />

恩。今天就大概这么多吧

下班前追加一个东西,关于设置登录之后不再返回登陆界面的设置

http://blog.csdn.net/crazy_yyyyy/article/details/51494524

只能说很好用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值