【问题标题】:How do I add background gradients to a fragment.xml class如何将背景渐变添加到 fragment.xml 类
【发布时间】:2014-01-08 14:01:03
【问题描述】:

我知道添加背景渐变是一件非常基本的事情,但我被抛出“根元素之后的文档中的标记必须格式正确”

我确信我正在做一些对你们中的许多人来说非常明显的事情,但如果我能在这里看到我的错误,我将不胜感激。

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/articlelist"
android:name="com.MSmith.test.ArticleListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context=".ArticleListActivity"
tools:layout="@android:layout/list_content"/>


<style android:background="#A9A9A9"/>

尝试将 android:background="" 添加到但没有显示任何错误,模拟器/图形显示没有变化。

【问题讨论】:

  • android:background="#A9A9A9" to frament 自己

标签: android xml android-fragments master-detail


【解决方案1】:

像这样定义一个drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="315"
        android:endColor="@color/mainMenuGradient_endColor"
        android:startColor="@color/mainMenuGradient_startColor" />

</shape>

并在您的片段根布局中将此可绘制对象设置为背景,您将拥有一个渐变。

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/articlelist"
android:name="com.MSmith.test.ArticleListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context=".ArticleListActivity"
tools:layout="@android:layout/list_content"
android:background="@drawable/yourdrawablehere"/> <----- this might work

或者直接在Fragment的xml-layout中添加

【讨论】:

  • 谢谢你非常及时,但是片段根布局在哪里,我现在已经放入应用程序中的drawable
猜你喜欢
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-26
  • 2014-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-04
相关资源
最近更新 更多