简体   繁体   中英

the same style.xml in two different Fragment not work

I have this Style.xml in res/values/values-v14 . In my manifest minSDK is 14.

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 14 theme customizations can go here. -->
     <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
     <item name="android:textColor">@color/donostiakirolak_texto_general</item>

</style>

<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/donostiakirolak_actionbar_blue</item>
</style>



<style name="DonostiakirolakListView">
    <item name="android:background">@color/donostiakirolak_fondo_listview</item>
    <item name="android:textColor">@color/donostiakirolak_texto_listview_title</item>


</style>

And i have two fragment very similar.

oneFragment onCreateView method:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {        
    setHasOptionsMenu(true);
    View view = inflater.inflate(R.layout.instalaciones_en_lista_fragment, container, false);

    lvInstalaciones = (ListView) view.findViewById(R.id.instalaciones_en_lista_fragment_lvInstalaciones);
    lvInstalaciones.setOnItemClickListener(this);

    InstalacionesEnListaConFlechayCategoriasAdapter ad = new InstalacionesEnListaConFlechayCategoriasAdapter(getActivity().getApplicationContext(), this.instalacionesConCategorias, tag);
    this.lvInstalaciones.setAdapter(ad);
    return view;
}

TwoFragment onCreateView method: ( it is the same! )

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.instalaciones_en_lista_fragment, container, false);

    lvInstalaciones = (ListView)view.findViewById(R.id.instalaciones_en_lista_fragment_lvInstalaciones);
    lvInstalaciones.setOnItemClickListener(this);

    InstalacionesEnListaConFlechayCategoriasAdapter adapter = new InstalacionesEnListaConFlechayCategoriasAdapter(getActivity().getBaseContext(), instalacionesConCategorias, tag);

    this.lvInstalaciones.setAdapter(adapter);
    return view;
}

this is instalaciones_en_lista_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/instalaciones_en_lista_fragment_lvInstalaciones"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        style="@style/DonostiakirolakListView">
    </ListView>

I specify style. Interestingly, the text display oneFragment is not the same color on the screen twoFragment. twoFragment is ok and oneFragment wrong.

Edited This is InstalacionesEnListaConFlechayCategoriasAdapter code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View v = convertView;
    Instalacion inst = items.get(position);
    String nombre = inst.getNombre();


    //Analizamos si es necesario inflar el layout de la categoria
    if(nombre.equalsIgnoreCase(pldTraducido) //PLD
       || nombre.equalsIgnoreCase(cpfTraducido) //CPF
       || nombre.equalsIgnoreCase(frcTraducido) //FRC
       || nombre.equalsIgnoreCase(frdTraducido) //FRD
       || nombre.equalsIgnoreCase(otrTraducido) //OTR
       || nombre.equalsIgnoreCase(pldTraducido) //PLD
       || nombre.equalsIgnoreCase(ppeTraducido) //PPE
       || nombre.equalsIgnoreCase(psrTraducido)){ //PSR //Para que todas las instalaciones no recorran todos los ifs, s epodria mejorar el código. con interaces items y item.isSecction

         if (convertView == null || convertView.findViewById(R.id.custom_todaslasinstalaciones_categoria_header_titulo)==null)
            {
            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inf.inflate(R.layout.custom_todaslasinstalaciones_header_categoria, null);
            v.setOnClickListener(null);
            v.setOnLongClickListener(null);
            v.setLongClickable(false);

            }
            TextView nombreCategoria = (TextView) v.findViewById(R.id.custom_todaslasinstalaciones_categoria_header_titulo);
                    nombreCategoria.setText(nombre);

    }

    else{
        if(tag.equalsIgnoreCase("DISTANCIA")){
            //Mostramos mojon y distancia
            //[Image+distancia][Nombre Instalación [Flecha]]
            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inf.inflate(R.layout.custom_todaslasinstalaciones_conflecha_mojon, null);
            TextView tvNombre = (TextView) v.findViewById(R.id.custom_todaslasinstalaciones_conflecha_mojon_tv_nombreinstalacion);
            tvNombre.setText(nombre);

            TextView tvTextoKm = (TextView) v.findViewById(R.id.custom_todaslasinstalaciones_conflecha_mojon_tv_texto_km);
            tvTextoKm.setText("km");

            TextView tvDistancia = (TextView) v.findViewById(R.id.custom_todaslasinstalaciones_conflecha_mojon_tv_distancia);
            tvDistancia.setText(inst.getDistancia());
        }else{

            //Sin mojon
            //[Nombre Instalación [Flecha]]
            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inf.inflate(R.layout.custom_todaslasinstalaciones_conflecha, null);
            TextView tvNombre = (TextView) v.findViewById(R.id.custom_todaslasinstalaciones_conflecha_tvnombreinstalacion);
            tvNombre.setText(nombre);

        }
    }
    return v;
}

and custom_todaslasinstalaciones_conflecha.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >


    <TextView
        android:id="@+id/custom_todaslasinstalaciones_conflecha_tvnombreinstalacion"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:paddingRight="50dp"
        android:paddingLeft="15dp"
        android:gravity="center_vertical"
    android:layout_toLeftOf="@+id/custom_todaslasinstalaciones_conflecha_img_flecha"
        android:text="Nombre instalación que pasa si el nombre d ela instalacion"
        android:textSize="18dp" 
        android:lines="4"
        android:ellipsize="marquee"/>

    <ImageView
               android:id="@+id/custom_todaslasinstalaciones_conflecha_img_flecha"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_action_next_item" />

</RelativeLayout>

如果通过“文本在屏幕上显示的oneFragment与屏幕上的twoFragment的颜色不同”来标记listView项目的textColor,那么也许您应该查看your_list_item.xml文件中的textColor属性或InstalacionesEnListaConFlechayCategoriasAdapter来更改项目文本颜色代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM