代码之家  ›  专栏  ›  技术社区  ›  Harindaka

Xamarin:如何在运行时将以下android主题应用于我的活动?

  •  0
  • Harindaka  · 技术社区  · 6 年前

    我有以下活动将主题指定为属性

    [Activity(Label = "PermissionsActivity", Theme = "@android:style/Theme.Translucent.NoTitleBar")]
    public class PermissionsActivity: Activity
    

    SetTheme 在里面 OnCreate

    3 回复  |  直到 6 年前
        1
  •  1
  •   Arvind Chourasiya    6 年前

    在中添加主题 style.xml 资源文件夹下的文件,而不是作为 int

    <style name="MyTheme" parent="Theme.Translucent.NoTitleBar">
    </style>
    

    this.SetTheme(Resource.Style.MyTheme);
    
        2
  •  0
  •   user10169672 user10169672    6 年前

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // Call setTheme before creation of any(!) View.
     setTheme(android.R.style.Theme_Dark);
    
    // ...
    setContentView(R.layout.main);
    

    For reference check this Link

        3
  •  0
  •   FreakyAli    6 年前

    现在在运行时,当您需要将这些添加到代码中时,它们可以如下使用:

    • 如果资源是一种样式,那么它在 Resource.Style.YourResourceName
    • Resource.Dimen.YourResourceName
    • Resource.String.YourResourceName
    • 如果资源是drawable文件夹下的图像,则它在中可用 Resource.Drawable.YourResourceName
    • 如果资源是mipmap文件夹下的图像,那么它在中可用 Resource.Mipmap.YourResourceName ,等等。

    注意:这些属性始终是整数。

    因此,您可以在活动中获得这样的效果:

    this.SetTheme(Resource.Style.MyTheme);
    

    this.Activity.SetTheme(Resource.Style.MyTheme);
    

    希望这有帮助,

    查询时还原。