android 主题元素映射方式

本文深入探讨了Android输入方法服务中主题选择与资源映射的实现原理,包括如何通过SDK版本选择合适的主题样式,以及如何利用资源文件自定义输入方法的全屏背景、进入与退出动画等关键元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//方式一:代码直接映射

\alps\frameworks\base\core\java\android\inputmethodservice\InputMethodService.java

@Override public void onCreate() {

mTheme =Resources.selectSystemTheme(mTheme,

               getApplicationInfo().targetSdkVersion,

                android.R.style.Theme_InputMethod,

               android.R.style.Theme_Holo_InputMethod,

               android.R.style.Theme_DeviceDefault_InputMethod);

super.setTheme(mTheme);

}

 

void initViews() {

mThemeAttrs =obtainStyledAttributes(android.R.styleable.InputMethodService);

mFullscreenArea.setBackgroundDrawable(mThemeAttrs.getDrawable(

                       com.android.internal.R.styleable.InputMethodService_imeFullscreenBackground));

}

 

\alps\frameworks\base\core\res\res\values-large\themes.xml

   <!-- Default theme for input methods (on API level 10 and lower),which is used by the

        {@linkandroid.inputmethodservice.InputMethodService} class.

        this inherits from Theme.Panel, but sets up IME appropriate animations

        and a few custom attributes. -->

    <stylename="Theme.InputMethod" parent="Theme.Panel">

       <itemname="android:windowAnimationStyle">@android:style/Animation.InputMethod</item>

       <item name="android:imeFullscreenBackground">@android:drawable/input_method_fullscreen_background</item>

       <itemname="android:imeExtractEnterAnimation">@android:anim/input_method_extract_enter</item>

       <itemname="android:imeExtractExitAnimation">@android:anim/input_method_extract_exit</item>

 

   <style name="Theme.Panel">

       <itemname="android:windowBackground">@android:color/transparent</item>

       <itemname="android:colorBackgroundCacheHint">@null</item>

       <item name="android:windowFrame">@null</item>

   </style>

 

\alps\frameworks\base\core\res\res\values\Attrs.xml

   <declare-styleable name="InputMethodService">

       <!-- Background to use for entire input method when it is being

            shown in fullscreen mode with the extract view, to ensure

            that it completely covers the application.  This allows,

            for example, the candidate view to be hidden

            while in fullscreen mode without having the application show through

            behind it.-->

       <attr name="imeFullscreenBackground" format="reference|color"/>

       <!-- Animation to use when showing the fullscreen extract UI after

            it had previously been hidden. -->

       <attr name="imeExtractEnterAnimation"format="reference" />

       <!-- Animation to use when hiding the fullscreen extract UI after

            it had previously been shown. -->

       <attr name="imeExtractExitAnimation"format="reference" />

   </declare-styleable>

 

\alps\frameworks\base\core\res\res\values\colors.xml

</style><drawable name="input_method_fullscreen_background">#fff9f9f9</drawable>

 

//方式二:资源映射:

\alps\mediatek\custom\k10\resource_overlay\generic_WIFIONLY\packages\apps\Contacts\AndroidManifest.xml

       <activity android:name=".activities.PeopleActivity"

           android:label="@string/people"

           android:theme="@style/PeopleTheme"

           android:uiOptions="splitActionBarWhenNarrow"

           android:clearTaskOnLaunch="true"

           android:launchMode="singleTop"

       >

 

\alps\mediatek\custom\k10\resource_overlay\generic\packages\apps\Contacts\res\values-sw600dp\styles.xml

   <style name="PeopleTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">

       <itemname="android:actionBarStyle">@style/ContactsActionBarStyle</item>

       <itemname="android:actionBarItemBackground">@drawable/action_bar_item_background</item>

       <itemname="android:actionBarWidgetTheme">@style/ContactsActionBarTheme</item>

</style>

 

\alps\frameworks\base\core\res\res\values\ themes.xml

   <!-- Variant of the holographic (light) theme that has a solid(opaque) action bar

        with an inverse color profile. The dark action bar sharply stands outagainst

        the light content. -->

<stylename="Theme.Holo.Light.DarkActionBar">

        <itemname="android:windowContentOverlay">@android:drawable/ab_solid_shadow_holo</item>

        <itemname="android:actionBarStyle">@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse</item>

        <itemname="actionBarWidgetTheme">@android:style/Theme.Holo</item>

</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

架构师训练营

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值