简单更改App主题

时间:2014-10-17 08:42:41

标签: android mobile android-studio themes

我正在尝试将应用主题更改为Light.NoTitleBar.Fullscreen(经典之光)。

AndroidManifest.xml :(我被告知首先添加空白活动并添加登录活动,然后交换名称LoginMain

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.helloworld" >
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_login"
        android:windowSoftInputMode="adjustResize|stateVisible" >
    </activity>
</application>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

</manifest>

activity_login.xml :(我使用和修改的登录活动模板。)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.administrator.helloworld.LoginActivity"
>

<!-- Login progress -->
<ProgressBar
    android:id="@+id/login_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="470dp"
    android:layout_height="470dp"
    android:layout_marginBottom="8dp"
    android:visibility="gone"/>

<LinearLayout
    android:id="@+id/email_login_form"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="1">

    <ImageView
        android:layout_width="350dp"
        android:layout_height="200dp"
        android:id="@+id/imageView"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/syncz"
        android:layout_marginTop="40dp"
        android:layout_marginBottom="90dp" />

    <TextView
        android:layout_width="79dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Login:"
        android:id="@+id/textView"
        android:textStyle="bold" />

    <AutoCompleteTextView
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/prompt_email"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:singleLine="true"
        android:layout_marginTop="16dp"
        android:textStyle="italic"
        android:layout_marginBottom="10dp" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:imeActionId="@+id/login"
        android:imeActionLabel="@string/action_sign_in_short"
        android:imeOptions="actionUnspecified"
        android:inputType="textPassword"
        android:maxLines="1"
        android:singleLine="true"
        android:layout_marginBottom="8dp"
        android:textStyle="italic" />

    <Button
        android:id="@+id/email_sign_in_button"
        style="?android:textAppearanceSmall"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="16dp"
        android:text="@string/action_sign_in"
        android:layout_weight="0.11"
        android:textSize="25dp" />

</LinearLayout>

</LinearLayout>

activity_main.xml :(尚未配置,稍后它将成为菜单。)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

styles.xml :(无变化)

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
</style>

</resources>

一般首页设计照片 - Imgur


最终编辑 - 事实证明,这样做的方法与我之前使用的命令相同但当时我在运行时遇到错误。我必须在不知情的情况下改变一些东西,我不知道,但好消息是它已经修复并且正在运行。

4 个答案:

答案 0 :(得分:2)

尝试在androidmanifest文件的应用程序标记中添加此代码:

android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

您也可以参考Create Project从头开始。在了解您可以参考Training Lessons

之后

为简单起见,请在mainfest文件中查看

android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

在styles.xml中检查:

parent="android:Theme.Light.NoTitleBar.Fullscreen"

答案 1 :(得分:0)

您可以将Light.NoTitleBar.Fullscreen与不具有应用主题的活动一起使用,以自定义应用主题使用this,对于那些您不希望标题栏将其应用于活动标签而不是应用中的活动标签

1)下载zip文件

2)将res文件导入res文件夹

然后在你的应用标签中应用这样的主题:

<application
 ....
 android:theme="@style/Theme.app theme" 
 .....

如果您想使用没有标题栏的活动打开应用程序,请执行此操作

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme=“@android:style/Theme.NoTitleBar.Fullscreen” 
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

答案 2 :(得分:0)

好吧,看起来,你是一个初学者,初学者总是过分关注主题的外观,就像我以前那样。只需按以下步骤操作: 1)决定你想制作什么样的应用程序(不要打扰UI) 2)不要观看您选择的任何教程的每个视频,而只需浏览那些对您的项目有帮助的视频。我知道人们热衷于观看他们感兴趣的一切。但要控制你的情绪并寻找有用的东西:p。 3)在某个阶段,你会意识到你已经足够了解你在那个阶段应该知道什么 4)您将自动遇到可以使用。

创建自己主题的情况

PS - 来自我的经验:p

答案 3 :(得分:0)

为了将主题更改为Light.NoTitleBar.Fullscreen,您需要在androidmanifest.xml文件中包含以下内容

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Light.NoTilteBar.Fullscreen"
   android:uiOptions="splitActionBarWhenNarrow">

您可以在Styles.xml文件中添加更多主题。对于此单击res文件夹 - &gt; values-&gt; styles

示例代码以获得一个想法:

styles.xml: -

<style name="AppTheme" parent="AppBaseTheme">

</style>

Androidmanifest.xml: -

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

所以在这里你可以看到这一行&lt; android:theme =“@ style / AppTheme”&gt;在androidmanifest文件中

“@ style”这意味着res文件夹中的样式xml文件 因此,在style.xml文件中,您可以添加更多主题作为您的选择