如何在Android

时间:2016-08-08 04:33:42

标签: android background

我试图让我的TextView在黑色背景上有白色文字。这就是我所拥有的:

                <TextView
                   android:id="@+id/items_category"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:text="Category"
                   style="@style/Category" />

在我的styles.xml中,我有:

                <style name="Category">
                   <item name="android:textColor">#FFFFFF</item>
                   <item name="android:textSize">40sp</item>
                   <item name="android:colorBackground">#000000</item>
                </style>

字体大小和颜色正确,但背景颜色不起作用。我究竟做错了什么?谢谢你的时间

2 个答案:

答案 0 :(得分:2)

试试这个:

<div class="content row">
        <div class="head-style col-md-12 col-sm-12 col-xs-12">
            <div class="title-pack col-md-12 col-sm-12 col-xs-12">
                <span class="line visible-sm-block"></span>
                <span class="visible-sm-block tittle-style">کتابخانه</span>
                <!-- <span class=" pull-right line visible-sm-block"></span> -->
            </div>
            <div class="row library-info">
                <div class="library-box col-md-9 col-sm-8 col-xs-12">
                    <div class="col-md-11 col-sm-11 col-xs-12 ">
                        <ul>
                                <li class="">
                                    <a href="images/gallery1/image-1.jpg" title="Item 1 title ..." data-desc="Item1 a small cake baked in a cup-shaped foil or paper case" rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-1.jpg" alt="Image description for search engins" />
                                        <h4>تراژدی تنهایی</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-2.jpg" title="Item 2 title ..." data-desc="Item 2 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-2.jpg" alt="Image description for search engins" />
                                        <h4>سرخ و سفید</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-3.jpg" title="Item 3 title ..." data-desc="Item 3 A small, chocolate-covered candy with a hard or soft center." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-3.jpg" alt="Image description for search engins" />
                                        <h4>پاییز فصل آخر سال است</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-4.jpg" title="Item 3 title ..." data-desc="Item 4 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-4.jpg" alt="Image description for search engins" />
                                        <h4>نوبت</h4>
                                        <p>10000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-1.jpg" title="Item 1 title ..." data-desc="Item1 a small cake baked in a cup-shaped foil or paper case" rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-1.jpg" alt="Image description for search engins" />
                                        <h4>تراژدی تنهایی</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-2.jpg" title="Item 2 title ..." data-desc="Item 2 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-2.jpg" alt="Image description for search engins" />
                                        <h4>سرخ و سفید</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-3.jpg" title="Item 3 title ..." data-desc="Item 3 A small, chocolate-covered candy with a hard or soft center." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-3.jpg" alt="Image description for search engins" />
                                        <h4>پاییز فصل آخر سال است</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-4.jpg" title="Item 3 title ..." data-desc="Item 4 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-4.jpg" alt="Image description for search engins" />
                                        <h4>نوبت</h4>
                                        <p>10000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-1.jpg" title="Item 1 title ..." data-desc="Item1 a small cake baked in a cup-shaped foil or paper case" rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-1.jpg" alt="Image description for search engins" />
                                        <h4>تراژدی تنهایی</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-2.jpg" title="Item 2 title ..." data-desc="Item 2 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-2.jpg" alt="Image description for search engins" />
                                        <h4>سرخ و سفید</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-3.jpg" title="Item 3 title ..." data-desc="Item 3 A small, chocolate-covered candy with a hard or soft center." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-3.jpg" alt="Image description for search engins" />
                                        <h4>پاییز فصل آخر سال است</h4>
                                        <p>15000 تومان</p>
                                    </a>
                                </li>
                                <li class="">
                                    <a href="images/gallery1/image-4.jpg" title="Item 3 title ..." data-desc="Item 4 A cake made of sweetened cottage cheese or cream cheese, eggs, milk, sugar, and flavorings." rel="lightbox[group1]">
                                        <img src="images/gallery1/thumb-4.jpg" alt="Image description for search engins" />
                                        <h4>نوبت</h4>
                                        <p>10000 تومان</p>
                                    </a>
                                </li>
                        </ul>   
                        <div style="clear:both;"></div>
                    </div>  
                </div>  
<!-- ~~~~~~ <>< ~~~~ <><  ~~~~ <>< ~~~~~~~~ Start of sidebar part ~~~~~~ <>< ><> ~~~~~ <><  ~~ <>< ~~~~~~~~  -->            
            <div class="sidebar col-md-3 col-sm-4 col-xs-12">
                <div class="sidebarbox ">

                    <div class=" library-category col-md-12 col-sm-12 col-xs-12">
                        <h3>دسته بندی کتاب</h3>
                            <div>
                                <div class="library-category-option">
                                    <a href="">زندگینامه</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">ادبیات</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">کودک و نوجوان</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">روانشناسی</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">هنر</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">علوم اجتماعی</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">اقتصاد</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">تجارت</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">مدیریت</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">گوناگون</a>
                                </div>
                                <div class="library-category-option">
                                    <a href="">همه</a>
                                </div>
                                <div style="clear:both;"></div>
                            </div>
                        </div>
                        <div class="search-sidebar col-md-12  col-sm-12 col-xs-12">
                            <h3>جستوجو کتاب</h3>
                            <div class="dark">
                                <form role="search" method="get" class="wproduct-search" action="">

                                    <span><input placeholder="جستجو کتاب" type="text" class="search square"><input type="button" value="Search"></span>
                                </form>
                            </div>
                        </div>
                        <div class="letter-news col-md-12  col-sm-12 col-xs-12">
                            <h3>خبرنامه</h3>
                            <form>
                                <input type="" name="" placeholder="نام شما" >
                                <input class="input-dis" type="" name="" placeholder="ایمیل شما" >
                                <button class="send-button center-margin">ارسال</button>
                            </form>
                            <div style="clear:both;"></div>
                        </div>
                    </div>
                </div>
                <div style="clear:both;"></div>
                </div>
            </div>
        </div>

您还可以引用颜色:

.content{
    padding: 0 20px;
}
.aboutus,
.news-index,
.book-library,
.head-style,
.double,
.best,
.pages{
    min-height: 230px;
    margin-top: 20px;
    margin-bottom: 20px;
}
.ourservice,
.besty,
.phisical-shop,
.library-info,
.about-us,
.writer-crit,
.gallery{
    margin-top: 23px;
    margin-bottom: 25px;
}
.ourservice-box > div,
.phisical-store > div,
.library-box > div,
.about-us-box > div,
.writer-crit-box > div,
.gallery-box > div{
    min-height: 1000px;
}
.library-box{
    min-height: 1200px;
    display: inline-block;
    padding: 0;
}
.sidebar{
    min-height: 600px;
    display: inline-block;
    padding: 0;
}
.sidebar .tab-content{
    margin-top: 60px;
}
.sidebarbox{
    width: 100%;
    min-height: 500px;
    float: left;
}
.best-sells,
.letter-news,
.news-sidebar,
.search-sidebar{
    height: 535px;
    padding-bottom: 20px;
    background: rgba(223,221,224,0.8);
}

或您自己定义的颜色:

<item name="android:background">#000000</item>

答案 1 :(得分:0)

如果您在任何视图中提供样式,那么它将继承您定义样式的所有属性..

现在,如果要更改任何属性,则必须在视图中定义它,以便覆盖该视图的该属性。

您可以在Textview中设置如下所示的背景颜色,这样它将覆盖样式背景属性的值:

<item name="android:background">#000000</item>