开发手机卫士第二天,自定义style,对话框

来源:互联网 发布:工业数据库 编辑:程序博客网 时间:2024/05/17 09:31

遇到问题:

1.在开发自定义组件对话框的时候,在activity页面填充时忘记了要是自己的view。直接用了findViewById,这样的话会报空指针的异常

一定要自己定义一个view private View view;,然后再监听对话框事件时候, view.findViewById。而不是直接 findViewById,直接findViewById会默认在

当前activity页面找,虽然不会报错,但是运行时出错

2.开发对话框时,最后忘记 builder.setView(view);
builder.show();

3,自定义文本样式(比如经常使用的标题)


  在values里有个styles.xml,在里面自定义样式,非常简单在style里面定义item

             <style name="text_title_style">

         <item name="android:textSize">20sp</item>
        <item name="android:background">#2266ff00</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:paddingTop">10dip</item>
        <item name="android:paddingBottom">10dip</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>

</style>

  引入的时候只需要

    <TextView
        style="@style/text_title_style"
        android:text="1.欢迎使用手机防盗" />


 


0 0