在布局文件中,可以看到各种控件如果是想要在程序中控制它,就需要给它分配一个ID,如下所示:
   
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Insert" />
第二行android:id="@+id/button1",这里的“+”号就是通知R.java,给增加一个Button资源。

但是在使用字符串时,就不需要上“+”号,如下:
   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
这里实际上是引用,对字符串的定义都在res/values/strings.xml文件中进行的。
安卓中资源ID的问题

在res资源文件夹里面,对控件的声明在布局文件中,对字符串的声明在strings.xml文件中,在布局文件不可以声明字符串,只能使用。

相关文章:

  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-11-28
  • 2021-06-01
  • 2021-11-17
  • 2021-05-28
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案