maoruibin / maoruibin/maoruibin.github.com

通过代码方式设置 selectableItemBackground 背景

Open
#66 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.