• 使用了Theme但是没有效果问题


    最近在开发过程中使用了theme移植Preference并使用了一些android样式,但是在自定义的Theme修改了相关参数后却无法实现

    可能有些朋友还不知道怎么用。这里也做个简要的使用方式说明。

    1. xml中使用样式。

    android:textAppearance="?android:attr/textAppearanceLarge"
    ?android:使用安卓内置样式。
            <TextView android:id="@id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true" android:text="Hellopss"
                android:ellipsize="marquee" 
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:fadingEdge="horizontal" />

    2.View中使用到xml

      setContentView(xml)

    3. 定义Theme

        <style name="AppTheme" parent="@style/AppThemsse">
    
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
            <!-- Text styles -->
            <item name="android:textAppearance">@style/TextAppearance</item>
            <item name="android:textAppearanceInverse">@style/TextAppearance.Inverse</item>
            <item name="android:textAppearanceLarge">@style/TextAppearance.Large</item>
            <item name="android:textAppearanceMedium">@style/TextAppearance.Medium</item>
            <item name="android:textAppearanceSmall">@style/TextAppearance.Small</item>
            <item name="android:textAppearanceLargeInverse">@style/TextAppearance.Large.Inverse</item>
            <item name="android:textAppearanceMediumInverse">@style/TextAppearance.Medium.Inverse</item>
            <item name="android:textAppearanceSmallInverse">@style/TextAppearance.Small.Inverse</item>
            <item name="android:textAppearanceButton">@style/TextAppearance.Widget.Button</item>
            <item name="android:textColorPrimary">#000079</item>
            <item name="android:textColorSecondary">#000079</item>
            <item name="android:textColorTertiary">@color/tertiary_text_light</item>
            <item name="android:textColorPrimaryInverse">@color/primary_text_dark</item>
            <item name="android:textColorSecondaryInverse">@color/secondary_text_dark</item>
            <item name="android:textColorTertiaryInverse">@color/tertiary_text_dark</item>
            <item name="android:textColorPrimaryDisableOnly">@color/primary_text_light_disable_only</item>
            <item name="android:textColorPrimaryInverseDisableOnly">@color/primary_text_dark_disable_only</item>
            <item name="android:textColorPrimaryNoDisable">@color/primary_text_light_nodisable</item>
            <item name="android:textColorSecondaryNoDisable">@color/secondary_text_dark_nodisable</item>
            <item name="android:textColorPrimaryInverseNoDisable">@color/primary_text_dark_nodisable</item>
            <item name="android:textColorSecondaryInverseNoDisable">@color/secondary_text_dark_nodisable</item>
            <item name="android:textColorHint">@color/hint_foreground_light</item>
            <item name="android:textColorHintInverse">@color/hint_foreground_dark</item>
            
        </style>
    
        <style name="TextAppearance">
            <item name="android:textColor">?android:textColorPrimary</item>
            <item name="android:textColorHighlight">#FFFF9200</item>
            <item name="android:textColorHint">?android:textColorHint</item>
            <item name="android:textColorLink">#5C5CFF</item>
            <item name="android:textSize">16sp</item>
            <item name="android:textStyle">normal</item>
        </style>

    theme修改该引用的样式

    4. Theme使用

    AndroidManifest.xml 中设置该Theme android:theme="**"

    5. 使用View

    (1)直接xml导入View

    (2)先new View(这样出现了所描述的问题)

            
            PreferenceScreen mPreferenceScreen = getPreferenceManager().createPreferenceScreen(getApplicationContext());
            Preference mPreference = new Preference(this);
            mPreference.setTitle("我的应用世界");
            mPreference.setSummary("测试自定义Preference");
            mPreference.setKey("hello");
            mPreferenceScreen.addPreference(mPreference);

    注意红色的地方,如果使用的是getApplicationContent()不知不觉中就出现无法使用theme了。

    惠存!

  • 相关阅读:
    静态导入
    OC中的Debug表达式
    友盟消息推送(一)
    Xcode7.0 更新完后,网络请求报错
    HTTP返回的状态码
    ios 通知监听App进入后台,然后再进入App(获取验证码的时间间隔)
    iOS保存model数据(自定义Model 可以存放到本地)
    tatableView 刷新
    iOS bounds和Frame的区别
    UIButton下面添加滑动的线
  • 原文地址:https://www.cnblogs.com/pandans/p/4154732.html
Copyright © 2020-2023  润新知