以编程方式进行一项具有两个主题的活动

我在以编程方式切换活动主题时遇到问题。我有一个路由器活动,该活动根据某些条件决定要路由的活动。路由器活动可以在两个时间打开:具有启动屏幕主题的应用程序启动时间,以及从某处调用startactivity以使用NoDisplay或Transparent主题做出路由器决定。我已经在清单中设置了启动主题,并且效果很好。但是在调用startactivity时,我无法在运行时更改为透明主题。它显示的是黑色背景色,而不是透明的。

Routeractivity:

override fun onCreate(savedInstanceState: Bundle?) {
    val transparent = intent.extras?.getBoolean("Need_Transparent")?:false
    if(transparent) setTheme(R.style.Theme_Transparent)
    super.onCreate(savedInstanceState)
    //no setContentView()
}

styles.xml

<style name="Apptheme" parent="Theme.AppCompat.Light.DarkactionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="coloraccent">@color/coloraccent</item>
</style>
<style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@android:color/holo_green_light</item>
</style>

AndroidManifest.xml:

<activity
        android:name=".Routeractivity"
        android:theme="@style/Theme.Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

那么我该如何使用两个主题来实现Routeractivity:Splash(清单中的默认设置)和Transparent主题(通过其他活动的startactivity打开)。

snowboyz 回答:以编程方式进行一项具有两个主题的活动

我正在用Java提供此解决方案,希望相同的逻辑也可以在Kotlin中工作,

设置主题的最佳方法是覆盖类中的资源主题,并使用@Override public Resources.Theme getTheme() { Resources.Theme theme = super.getTheme(); if(useAlternativeTheme){ theme.applyStyle(R.style.AlternativeTheme,true); } // you could also use a switch if you have many themes that could apply return theme; } 方法中存在的相同逻辑

$("#details").jqGrid({
    mtype: "POST",url: gridUrl,datatype: 'json',height: "100%",width: "100%",autowidth: true,shrinkToFit: true,colNames: ["Login Time","Ip Address","Login Status","Error Description"],colModel: [
        {

            index: 'loginTime',name: 'loginTime',formatter: returnLoginTime,width: 30,sorttype:'text'

        },{
            index: 'ipAdd',name: 'ipAdd',formatter: returnIpAdd,sortable: false,search: false

        },{
            index: 'loginStatus',name: 'loginStatus',formatter: returnStatus,{                                
            index: 'errorDesc',name: 'errorDesc',formatter: returnErrorDesc,search: false

        }
    ],rowNum: 10,rowList: [20,50,100,200,500],gridview: true,pager: "#pager",gridComplete:

                function () {
                $('.ui-jqgrid-labels').attr("height","35");
            },loadError: function (jqXHR,textStatus,errorThrown) {
   },jsonReader: {
        repeatitems: false
    },viewrecords: true,sortable:true,sortorder: "desc",caption: "",recordpos: 'right',pgbuttons: true,pginput: true,hiddengrid: false,grouping: false,multiselect: false,loadonce: true,emptyrecords: "No records to display",});
   $('#details').jqGrid(
       'filterToolbar',{autosearch: true,stringResult: false,ignoreCase: true,searchOnEnter: false,defaultSearch: "cn"});
本文链接:https://www.f2er.com/3017121.html

大家都在问