我可以对最新版本的Android Studio创建的新空白活动进行最简单的更改,以使应用程序全屏显示?
我想创建一个全屏Android应用程序.我正在使用Android Studio. 这篇文章建议我添加一行如...
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
...到AndroidManifest.xml文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lexogram.james.blackslate" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.lexogram.james.blackslate.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,应用程序编译但在启动时崩溃.如果我删除该行,该应用程序运行正常,但使用操作栏和标题栏,其他用户也会注意到.
这是我第一次尝试创建Android应用程序,因此我的应用程序几乎不会改变原始的Hello World示例.
编辑:我创建了一个新项目,并对其进行了一次更改.以下是错误日志的摘录:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lexogram.james.test/com.lexogram.james.test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...
Run Code Online (Sandbox Code Playgroud)
注意:我正在测试旧的三星SGH-T499Y,运行Android 2.2(Froyo)
我已经突破了这个问题.我需要做的是,AlertDialog在我的Android应用程序中更改所有s 的样式- 对话框背景需要是white-ish,文本需要是black-ish.我尝试创建了很多样式,主题,并从代码,清单等应用,但没有成功,关于内部的文本颜色AlertDialog.现在,我有最简单的代码,设置如下:
表现:
Run Code Online (Sandbox Code Playgroud)<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
styles.xml:
Run Code Online (Sandbox Code Playgroud)<style name="AppTheme" parent="AppBaseTheme"> <item name="android:alertDialogStyle">@style/DialogStyle</item> </style> <style name="DialogStyle" parent="@android:style/Theme.Dialog"> <!-- changing these background stuff works fine --> <item name="android:bottomBright">@android:color/white</item> <item name="android:bottomDark">@android:color/white</item> <item name="android:bottomMedium">@drawable/dialog_footer_bg</item> <item name="android:centerBright">@android:color/white</item> <item name="android:centerDark">@drawable/dialog_body_bg</item> <item name="android:centerMedium">@android:color/white</item> <item name="android:fullBright">@color/orange</item> <item name="android:fullDark">@color/orange</item> <item name="android:topBright">@color/green</item> <item name="android:topDark">@drawable/dialog_header_bg</item>
下面列出的项目不起作用(请阅读我在每个元素上面的评论):
Run Code Online (Sandbox Code Playgroud)<!-- panelBackground is not getting set to null, there is something squarish around it --> <item name="android:panelBackground">@null</item> <!-- Setting this textColor doesn't seem to have any effect at …
我想在我的应用程序中使用Material Theme,其最低sdk版本为8.根据文档 - "材料主题仅在Android 5.0(API级别21)及更高版本中可用.v7支持库提供主题的材料设计样式一些小部件和支持自定义调色板." 如果我在项目中添加v7支持库,这是否意味着我可以使用它?因为添加此库后我收到以下错误:
android:Theme.Material.Light需要API级别21(当前最小值为8).
或许我理解错了什么?任何建议将不胜感激.提前致谢.
Android风格和主题似乎总是让我头晕目眩.我想在我的应用程序中使用不同版本的Android的Holo UI.所以我决定通过浏览源来提取必要的资源.
我遇到了以下情况android-15\data\res\values\themes.xml,我很困惑究竟是什么'继承',从哪里来:
<style name="Theme.Holo.Light" parent="Theme.Light">
...
...
</style>
Run Code Online (Sandbox Code Playgroud)
如果要继承自己定义的样式,则不必使用该
parent属性.相反,只需将要继承的样式的名称添加到新样式的名称前面,并用句点分隔.
但是从上面的代码来看,它似乎Theme.Holo.Light是继承Theme.Holo而来的Theme.Light.
这是如何工作的,或者我没有正确阅读的内容?
我试图获得一个用户选择的主题,感觉我很沮丧.在AndroidManifest.xml工作中定义主题应该是,但(尽我所知)不能根据应用程序首选项更改:
<application
android:theme="@style/theme_sunshine"
android:icon="@drawable/icon"
android:label="@string/app_name">
Run Code Online (Sandbox Code Playgroud)
或者,在每个活动中动态设置它也可以:
someChosenTheme = PreferenceManager.getDefaultSharedPreferences(this).getString("themePreference", "theme_twilight");
setTheme(someOtherChosenTheme);
Run Code Online (Sandbox Code Playgroud)
但这看起来很混乱,我宁愿在一个地方设置整个应用程序的主题.我的第一个想法是在我的主要活动启动并在那里执行时抓住应用程序上下文:
getApplicationContext().setTheme(R.style.theme_dummy);
Run Code Online (Sandbox Code Playgroud)
我可以说,这应该是诀窍,但实际上它没有做任何事情 - 整个应用程序都有默认的Android风格.以上是否有效,如果是的话,我可能会做一些其他的愚蠢行为吗?
如果重要的话,我在API级别3工作.正确方向的产品非常感谢!
我使用灯光主题创建了一些项目,现在我想将它改为黑暗,我无法弄清楚如何做到这一点.顺便说一句,我不是在询问如何在代码中执行此操作,而是如何更改项目的默认主题.
我制作了一些支持多个主题的应用程序,但是当用户切换主题时我总是不得不重新启动应用程序,因为setTheme()之前需要调用它setContentView().
我没关系,直到我发现这个应用程序.它可以在两个主题之间无缝切换,也可以使用过渡/动画切换!

请给我一些关于如何实现(以及动画)的提示.谢谢!
我想让用户在几个不同的主题之间做出选择,并且想知道这是否是一种正常的做事方式.我用这种方法进行了一些测试并且它有效,但我认为可能有更好的方法并认为它可能会在以后引起一些问题,所以想问一下.
我正在考虑为每个主题创建一个不同的布局,并且onCreate只是为setContentView()方法切换.我首先加载一个保存的SharedPreference值(整数),具体取决于显示相应布局的值.显然,用户可以SharedPreference使用按钮或其他内容更改值.
由于这些布局基本相同但颜色不同,我想TextViews在每个布局文件中为我和其他视图使用相同的ID .我的主要问题是这会导致问题吗?
抱歉没有代码的文本墙.我想对这种情况大致了解良好做法.提前致谢.
我有一个工具栏,我使用,并设置标题:
((ActionBarActivity)getActivity()).getSupportActionBar().setTitle("Home");
Run Code Online (Sandbox Code Playgroud)
有没有办法将颜色从黑色变为白色?
我尝试制作自己的主题并在xml中设置它,但没有骰子:
<resources>
<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColorSecondary">@color/secondary_text</item>
</style>
<style name="Widget.MyApp.ActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/primary</item>
<item name="theme">@style/ThemeOverlay.MyApp.ActionBar</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#FFFFFF</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
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:background="#e5e5e5"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MyApp.ActionBar">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/statsSpin"
android:spinnerMode="dropdown"
android:textColor="#FFFFFF"/>
</android.support.v7.widget.Toolbar>
<ListView
android:id="@+id/yourStats"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="0px"
android:divider="@null"
>
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我想让我的活动全屏显示状态栏,就像这张图片一样:
我在manifest内部activity标记中使用了此代码:
'android:theme="@style/Theme.AppCompat.Light.NoActionBar"'
Run Code Online (Sandbox Code Playgroud)
但我的观点并不是从状态栏开始的,它看起来像这样:
我怎样才能让自己activity看起来像第一个?
android android-theme android-activity android-fullscreen android-statusbar