Android学习笔记之Theme主题的修改设置

(1)布局文件

<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: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=".MainActivity" >

    <!-- 普通的样式使用方法 -->

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="31dp"
        android:text="@string/hello_world" />

    <!-- 自定义的样式使用方法 -->

    <TextView
        android:id="@+id/textView1"
        style="@style/CodeFont.RED.BIG"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        style="@style/buttonStyle"
        android:layout_alignLeft="@+id/textView2"
        android:layout_centerVertical="true"
        android:text="Button"
        android:textColor="@color/textColor" />

</RelativeLayout>

(2)在values中新建xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:typeface">monospace</item>
    </style>

    <style name="CodeFont.RED">
        <item name="android:textColor">#00FF00</item>
    </style>

    <style name="CodeFont.RED.BIG">
        <item name="android:textSize">20sp</item>
    </style>

    <style name="buttonStyle">
        <item name="android:textColor">#00FF00</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginTop">48dp</item>
        <item name="android:layout_marginLeft">148dp</item>
    </style>

    <color name="textColor">#ACBDEC</color>

    <!-- 自定义主题 需要在清单文件中修改Android默认的主题 -->
    <color name="custom_theme_color">#b0b0ff</color>

    <style name="CustomTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/custom_theme_color</item>
        <item name="android:colorBackground">@color/custom_theme_color</item>
    </style>

</resources>

(3)如果要修改Android默认的主题需要在清单文件中修改,下图圈出的位置就是需要修改的地方

(4)其他问阿金都可以默认无需修改!

时间: 2024-08-27 23:45:33

Android学习笔记之Theme主题的修改设置的相关文章

Android 学习笔记之切换主题

首先要有主题颜色 theme_color.xml 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 4 <!--红--> 5 <color name="red">#FF6347</color> 6 <color name="dark_red">#F4511E</color> 7 &

Android学习笔记----闪屏主题

<!--闪屏主题--> <style name="welcome" parent="AppTheme"> <!--窗口透明--> <item name="android:windowIsTranslucent">true</item> </style>

Android学习笔记之mainfest文件中android属性

Android学习笔记之mainfest文件中android属性 - Impossible is nothing - 博客频道 - CSDN.NET 以前的零散笔记, 共享一下, 有错误的地方还请指正. android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务.---------------------------------------------------------------------------------

[Android学习笔记]Unable to execute dex Multiple dex files define:xxxx 问题

不同情况可能会出现这个问题,我遇到的问题是: 引入的多个jar包中,其中可能是第三方的SDK,但是其中可能使用了比较流行的开源框架,此时你项目中就有两套包名一样的代码,编译没问题,部署到手机之后就报如上错误 解决办法是: 把第三方jar包包含的开源代码删掉即可 比如: 项目中使用了android-async-http.jar , 同时引入 xxxxx.sdk.jar , 而由于xxxxx.sdk.jar中也引入了android-async-http.jar所以出现以上错误 解决步骤: 1.修改x

Pro Android学习笔记(二九):用户界面和控制(17):include和merge

xml控件代码重用:include 如果我们定义一个控件,需要在不同的layout中重复使用,或者在同一个layout中重复使用,可以采用include的方式.例如定义my_button.xml如下 <?xml version="1.0" encoding="utf-8"?> <Button xmlns:android="http://schemas.android.com/apk/res/android"     androi

Android学习笔记(四一):SQLite的使用

SQLite是非常流行的嵌入式关系型数据库,轻载,速度快,而且是开源.在Android中,runtime提供SQLite,所以我们可以使用SQLite,而且是全集的SQLite.SQLite提供SQL接口,和一般的数据库一样.但是Android的API不采用JDBC,JDBC消耗太多的资源. SQLite支持绝大部分SQL-92标准,不支持:FOREIGN KEY constraints, nested transactions, RIGHT OUTER JOIN, FULL OUTER JOI

Android学习笔记(四二):SQLite、ListView、ContextMenu

继续上一个例子,结合ListView中对SQLite进行操作. 通过CursorAdapter在ListView中的数据呈现 在上一个例子中,我们可以对SQLite中的数据库进行增删改查,将数据读到游标Cursor中,然后一一读出.在Android中可以通过CursorAdapter直接将数据映射到ListView中,如下处理: public class Chapter22Test1 extends ListActivity{    private SQLiteDatabase  db = nu

Android学习笔记(四三):文件访问

之前我们学习了通过preference和SQLite数据库进行数据存储,也可以通过文件方式.文件可以是在应用打包时预置,也可以是应用所生成. 文件访问有两种方式:一:静态数据的文件可以防止在res/raw中,这些文件是只读的,只有在应用版本升级的时候进行修改,或者我们先读出这些数据,通过 reference的方式来处理,这样以后可以进行修订,但是这种方式,会有两份数据保存.二:另一种方式是通过URL访问文件,动态数据的读取也可以采用SQLite3的方式. res/raw/下静态文件的读取 在re

Android学习笔记(十九):建立自己的ListView

在之前的例子中,我们通过设置adapter的getView()来编写我们所希望的UI,然而在面向对编程中,我们希望能够创建自己的ListView,例如类的名字为com.wei.android.learning.RatingView,只要在XML中用我们自己的RatingView对ListView来替代,就可以实现我们的风格,并前在源代码中向使用ListView一样简单调用就可以了. 实现的目标 在Android XML文件中,可以如下调用我们的RatingView: <com.wei.andro