• 日志12.03


    Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库。可以将一个 JSON 字符串转成一个 Java 对象,或者反过来。

    示例代码:

    Gson gson = new Gson();

    int[] ints = {1, 2, 3, 4, 5};

    String[] strings = {"abc", "def", "ghi"};

    (Serialization) gson.toJson(ints);     ==> prints [1,2,3,4,5]

    gson.toJson(strings);  ==> prints ["abc", "def", "ghi"]


    Intent android.content.Intent.putExtra(String name, Serializable value)

    Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll". Parameters:nameThe name of the extra data, with package prefix.valueThe Serializable data value.Returns:Returns the same Intent object, for chaining multiple calls into a single statement.See Also:putExtrasremoveExtragetSerializableExtra(String)


    LayoutInflater android.view.LayoutInflater.from(Contextcontext)

    Obtains the LayoutInflater from the given context.


    Object android.content.Context.getSystemService(Stringname)

    Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are: LAYOUT_INFLATER_SERVICE("layout_inflater")A android.view.LayoutInflater for inflating layout resources in this context.


    Inflater英文意思是膨胀,在Android中应该是扩展的意思吧。 LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件。

    两种方法可以得到LayoutInflater对象:from方法和getSystemService方法。以下两条语句等效:

    this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.inflater = LayoutInflater.from(context);

    android源码中显示from方法中使用到getService方法。


    在TextView中使用padding属性

    android:paddingLeft="15dip"
    android:paddingRight="10dip"
    android:paddingTop="6dip"
    android:paddingBottom="10dip"

    添加9.png图片作为背景图片

    android:background="@drawable/bg_inbox"

    其中bg_inbox在drawable中以xml格式出现 即drawable/bg_inbox.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="@drawable/bg_inbox_pressed" />
        <item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/bg_inbox_pressed" />
        <item android:drawable="@drawable/bg_inbox_normal" />
    </selector>

    在bg_inbox.xml文件中定义了不同状态时 显示不同的图片作为背景图片

    其中bg_inbox_normal和bg_inbox_pressed都是9派图!

  • 相关阅读:
    一些正则表达式
    iOS汉字中提取首字母
    flutter 按钮弹簧动画AnimationController
    In iOS 14+,debug mode Flutter apps can only be launched from Flutter tooling,IDEs with Flutter plugins or from Xcode.
    Failed to connect to raw.githubusercontent.com port 443: Connection refused
    iOS组件库创建(二)
    iOS组件库创建(一)
    同个电脑多个ssh key的配置
    网络相关总结
    flutter 热更新实现方案—UI资源化(二)
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/2800229.html
Copyright © 2020-2023  润新知