android - Android Studio:“无法执行重构。无法重命名此元素”
问题描述
我想更改图形的名称,但android studio显示错误:
“无法执行重构。无法重命名此元素”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/name"
android:textAlignment="center"
style="@style/NameStyle" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/btn_star_big_on"
/>
</LinearLayout>
重构仅在id
窗口中起作用:
为什么它在 XML 代码中不起作用?
这是 Kubuntu 20.04 LTS 上的第一个项目。
解决方案
您正在尝试重命名 android 平台的内置可绘制对象,而您发布的教程屏幕截图正在尝试重命名视图的 id
我的意思是
具有@android:
as 前缀的资源是在 android 平台中构建的资源,因此无法重构或重命名,并且您的屏幕截图正试图像这样重命名。您可以看到对话框标题Rename xyz and its occurence to
,指示您尝试重命名的元素
<ImageView
android:id="@+id/imageView" // This is being changed in the screenshot
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/btn_star_big_on" // You are trying to change this
推荐阅读
- java - Tomcat Config - JAVA_OPTS 和连接器中的密钥库/信任库之间的区别
- javascript - 从数据库中获取字段的实时值(Mysql)
- python - 三角形的算法任务
- microsoft-teams - 如何更改 Microsoft Teams 应用程序的所有者?
- perl - Perl 邮件附件文件大小限制
- php - PHP查找与数组中任何日期都不匹配的给定日期的壁橱日期
- javascript - 无法将参数传递给函数
- r - unlist() 对数据框使用时会产生意想不到的结果
- javascript - 如何设置不同域的 iframe 的 SessionStorage
- python - 我正在尝试像功能应用一样发出警报,但它一直在等待