How to find all hardcoded dimensions both in xml layout files and in code in Android Studio? I want to move them over to dimens.xml.
Basically, I want something like https://stackoverflow.com/a/39130143, but for dimensions instead of strings.
How to find all hardcoded dimensions both in xml layout files and in code in Android Studio? I want to move them over to dimens.xml.
Basically, I want something like https://stackoverflow.com/a/39130143, but for dimensions instead of strings.
This should work -
Press Ctrl + Shift + F
or Cmd + Shift + F
(in mac) to search in project.
Go to Options and choose Regular Expression.
Now search "((\d)+)dp"
in search bar which should give you all the hardcoded dimensions.
If you have dimensions as decimal values you can change the regex pattern accordingly. This one worked in my case. Also, if you want to search in specific area, you can do that too with this method. Thanks.
You can search all the hard coded dimension in Android studio using Find in path.
Go to
Edit > Find > Find in path
In option tab ->
*.xml
And you can start the search now, add \ddp
or [0-9]dp
in Text to find.
Done you can see all the usage.
I think you have to create the custom lint for that, since currently it can check for 0dp
in code and use of pixel instead of dimension.