【问题标题】:Simple change of App Theme应用主题的简单更改
【发布时间】:2018-04-29 20:09:20
【问题描述】:

我正在尝试将 App Theme 更改为 Light.NoTitleBar.Fullscreen (Classic Light)。

AndroidManifest.xml:(我被告知先添加一个空白 Activity 并添加登录 Activity,然后交换名称 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


最终编辑 - 事实证明,执行此操作的方法与我之前使用的命令相同,但当时我在运行它时遇到错误。我一定是在不知不觉中改变了一些东西,我不知道,但好消息是它已经修复并且正在运行。

【问题讨论】:

    标签: android mobile android-studio themes


    【解决方案1】:

    尝试将此代码添加到androidmanifest文件的application标签中:

    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"
    

    【讨论】:

    • 在来到这里之前尝试过 :) 它给了我一个错误。 ://
    • 给我你要我检查的文件的名称,我会立即发布! :)
    • 现在已添加到帖子中。目前正试图让我的模拟器工作......对不起
    • 错误在 androidmanifest 文件中:尝试在应用程序标签中添加这一行:- android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" > (在您的代码中是android:theme="@style/AppTheme" ,所以改变它)在 styles.xml:-parent="android:Theme.Light.NoTitleBar.Fullscreen" 中检查这个
    • 嗯,你知道什么......它实际上是出于某种原因。我向你发誓,我今天早些时候完全尝试过这个命令! :)
    【解决方案2】:

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

    创建自己的主题的情况。

    PS - 根据我的经验:p

    【讨论】:

    • 非常感谢,我一定会考虑的!
    【解决方案3】:

    为了将主题更改为 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 文件夹->values->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" >
    

    所以在这里你可以在 androidmanifest 文件中看到这一行

    "@style" 表示 res 文件夹中的样式 xml 文件 因此,在 style.xml 文件中,您可以添加更多主题作为您的选择

    【讨论】:

    • 所以你的意思是我可以进入 styles.xml 添加另一个
    • 在我看来,作为一个初学者,这是一个很好的入门网站(developer.android.com/guide/topics/ui/themes.html).It 对基本概念有很大帮助.....主题是应用于整个 Activity 或应用程序的样式,而不是而不是单独的 View (如上例所示)。当一个样式被应用为主题时,Activity 或应用程序中的每个 View 都会应用它支持的每个样式属性。例如,您可以应用相同的 CodeFont 样式作为主题对于一个活动,然后该活动内的所有文本都将具有绿色等宽字体。
    【解决方案4】:

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

    1) 下载压缩文件

    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>
    

    【讨论】:

    • 我打开应用程序的想法是打开一个没有操作栏或任何东西的页面,只有顶部/中间的徽标和下面的登录字段:) 我似乎找不到你有用的工具:(
    • 将 Light.NoTitleBar.Fullscreen 添加到启动器活动
    • 明白了吗?如果您不这样做,请告诉我
    • 我会在 10-20 分钟内知道,在 2 gb RAM 上工作很困难 :) Android Studio + Emulator 占用了我 93% 的内存 :D
    • 好吧,我试过你的方法,但似乎无法奏效。我现在会在帖子中发布我的一些文件:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2013-02-12
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多