【问题标题】:Mixed Themes in Android LayoutAndroid 布局中的混合主题
【发布时间】:2012-03-06 02:22:58
【问题描述】:

嗯。我有一个包含三个页面的 ViewPager 的 Activity。

活动正在使用浅色主题。我已经在清单中设置了

          <!-- PANTALLA PEDIDO-->
              <activity android:screenOrientation="portrait"
                    android:name="com.adelco.carro.Pedido"
                    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
                    <intent-filter>
                      <action android:name="com.adelco.carro.Pedido" />
                      <category android:name="android.intent.category.DEFAULT" />  
                    </intent-filter>
          </activity>

前两页看起来正确...这是第一页的屏幕截图:

这是第三页的截图:

妈的!为什么 TextViews 采用黑色主题颜色? ViewPager 的页面是一个片段,应该继承父活动的主题...

我该怎么办?我不想强制文本颜色.....

P.S:我在其他 Activity 中有另一个 ViewPager,颜色还可以……这太奇怪了

更多代码: 活动布局(有用的代码)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
      <RelativeLayout android:layout_width="match_parent"
                      android:layout_height="match_parent">
                <android.support.v4.view.ViewPager
                            android:layout_alignParentTop="true" 
                            android:id="@+id/pager_informacion"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">
                </android.support.v4.view.ViewPager>
    </RelativeLayout>
</LinearLayout>

片段布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
        <TextView android:text="Artículos"
                  android:layout_width="match_parent" 
                  android:layout_height="wrap_content"
                  android:textSize="28sp"
                  android:textStyle="bold"
                  android:gravity="center_vertical|center_horizontal"
                  android:textAppearance="?android:attr/textAppearanceMedium">
        </TextView>
        <FrameLayout android:layout_width="match_parent"
                     android:layout_height="0dip"
                     android:layout_weight="1" >
                <ListView android:id="@+id/lista_articulos"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:dividerHeight="1dp"
                          android:divider="@color/negro">
                </ListView>
        </FrameLayout>
</LinearLayout>

以及适配器布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <ImageView android:layout_width="wrap_content"
               android:layout_height="match_parent"
               android:scaleType="fitXY"
               android:id="@+id/iv_tipo_producto">
    </ImageView>
    <RelativeLayout android:layout_width="match_parent"
                    android:layout_height="match_parent">
        <TextView android:id="@+id/tv_descripcion" 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_alignParentLeft="true"
                  android:textStyle="bold"
                  android:textSize="16sp"
                  android:paddingLeft="5dp"
                  android:paddingRight="5dp">
        </TextView>
    </RelativeLayout>
</LinearLayout>

如你所见,代码很简单……我不明白这个问题。

【问题讨论】:

  • 布局上 TextView 的 textColor 属性似乎被覆盖了。也许您已经应用样式并更改了颜色?请添加 XML 布局的代码。
  • 我不这么认为...我没有使用任何颜色属性...布局的颜色是主题的“默认”颜色...
  • 尝试在适配器布局中将属性 textColor="@color/negro" 添加到 TextView。
  • 嗯...这是“简单易行”的解决方案...但是如果将来我想更改主题,那么这部分会看起来很难看,因为所有应用程序(除了这个页面这个片段的)正在遵循主题的配色方案......
  • 这样显示正确的颜色?

标签: android android-activity themes android-viewpager


【解决方案1】:

我认为问题在于调用方法填充listView的方式。很可能是传递给应用的上下文不正确并且不保留应用主题。

尝试传递 Activity 上下文,而不是调用 getAplicacionContext()。

像这样:

dataSource = new MyCursorAdapter(getActivity(), R.layout.myrow, data,
        fields, new int[] { R.id.field1, R.id.field2 });

更多信息:Custom ListView in Fragment not adhering to parent theme

希望对你有帮助。

【讨论】:

  • 是的!....我正在使用“getActivity().getApplicationContext()”并将其更改为“getActivity()”....现在可以使用了!!!谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
  • 2020-04-30
  • 2014-03-06
  • 1970-01-01
相关资源
最近更新 更多