maoruibin / maoruibin/maoruibin.github.com
通过代码方式设置 selectableItemBackground 背景
Open
Nobody has claimed this yet.
trick
- Dominant language
- HTML
- Stars
- 22
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
xml 布局中设置按下背景
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingRight="10dp">
代码设置
val outValue = TypedValue()
holder!!.itemView.context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)
holder!!.itemView.setBackgroundResource(outValue.resourceId)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides only XML and Kotlin snippets, with no repository file, test, or explicit expected result. Start by reproducing the difference between the XML background and the programmatic background, then confirm the intended Android behavior and document a verified resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100