今天所学习的内容为向项目中添加图标资源,以及直接在XML文件中引用资源。
首先将图标文件放入到资源目录中,然后在activity_quiz.xml中引用资源,具体代码如下:
<?xml version = “1.0” encoding = “utf-8”?> < LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android :layout_width = “match_parent” android :layout_height = “ match_parent“ android :gravity = ”center“ android :orientation = ”vertical“ > < TextView android :id = “@ + id / question_text_view” android :layout_width = “wrap_content” android :layout_height = “wrap_content” android :padding = “24dp” /> < LinearLayout android :layout_width = “wrap_content” android :layout_height = “wrap_content” android :orientation = “horizontal” > < button android :id = “@ + id / true_button” android :layout_width = “wrap_content” android :layout_height = “wrap_content” android :text = “@ string / true_button” /> < button android :id = “@ + id / false_button” android :layout_width = “wrap_content” android :layout_height = “wrap_content” android :text = “@ string / false_button” /> </ LinearLayout > < 按钮机器人:ID = “@ + ID / next_button” 机器人:layout_width = “WRAP_CONTENT” 机器人:layout_height = “WRAP_CONTENT” 机器人:文本= “@串/ next_button” 机器人:drawableRight = “@绘制/ ARROW_RIGHT” 机器人:drawablePadding = “4dp” /> </ LinearLayout >
最终在模拟器上运行结果如下: