zoukankan      html  css  js  c++  java
  • 格局中@null的代码实现方式

          布局中通常会用到@null。如RadioButton常用的技巧通过RadioGroup实现Tab,需要设置android:button="@null"。如果要在代码中动态创建控件,android中并不能找到相关的属性或方法。搜索均无解决办法,最后想到一个变通的方法:通过透明色获取drawable。

    setButtonDrawable(getResources().getDrawable(android.R.color.transparent))

     

       实际还是可以通过布局的方法来动态创建控件。先创建一个RadioButton的rb.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:button="@null" >
    
    </RadioButton>

     再在代码生成RadioButton

     RadioButton rb =(RadioButton)LayoutInflater.from(getContext()).inflate(R.layout.rb, null);

     这种方式的好处是样式等属性可以在布局中统一指定省的查sdk寻找相关属性的设置方法。

  • 相关阅读:
    链表的常用操作
    android简易论坛的制作
    Bmob后端云的使用
    马哥第九周
    马哥第八周
    马哥第七周
    马哥第六周
    马哥第五周
    马哥第四周
    马哥第三周
  • 原文地址:https://www.cnblogs.com/kobe8/p/3755140.html
Copyright © 2011-2022 走看看