我在布局中有一个textview,我将单击侦听器设置为布局,并且在按下布局时更改了布局的颜色。但是我想将textview的背景设置为透明,但是不能。它使用窗口的背景(窗口的背景为灰色,我的布局的背景为白色)而不是布局的背景。
<LinearLayout android:layout_width="match_parent"
android:layout_height="50dp"
style="@style/TestLayout">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Test"
android:background="@android:color/transparent"/>
</LinearLayout>
在
styles.xml
中<style name="TestLayout" parent="AppTheme.NoActionBar">
<item name="android:background">@drawable/selector_test_small_layout</item>
</style>
在
selector_test_small_layout
中<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/s_pressed_layout" />
<item android:state_hovered="true" android:state_enabled="true"
android:drawable="@drawable/s_pressed_layout"/>
<item android:state_enabled="true" android:drawable="@drawable/s_color_primary"/>
<item android:state_enabled="false" android:drawable="@drawable/s_color_primary"/>
</selector>
更新:对不起,我的xml还不够。明天我将正确更新它Y_Y。现在我没有源代码,只有图片
更新:我在styles.xml中包含了更多内容
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentOverlay">@null</item>
<item name="colorPrimary">@color/colorPrimary</item>
**<item name="android:windowBackground">@color/setting_divider</item>**
</style>
在AndroidManifest.xml中
<application
android:name=".TestApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
**android:theme="@style/AppTheme**">
....
</application>
最佳答案
我检查了上面添加的代码,根本看不到任何问题。您能否分享屏幕快照以指出确切的问题。您也可以尝试在TextView上设置background =“ @ null”。
关于android - 当它是布局的子级时,如何使textview背景透明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42832879/