理解android的风格和布局
我对安卓非常陌生 这是我的主要活动:理解android的风格和布局,android,android-layout,android-studio,android-styles,Android,Android Layout,Android Studio,Android Styles,我对安卓非常陌生 这是我的主要活动: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first_screen); } 这是main.xml文件 <RelativeLayout xmlns:android="http://sche
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_screen);
}
这是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: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="m.com.a0726.firstScreen">
</RelativeLayout>
最后,这是我的风格:
<style name="AppTheme" parent="AppParent">
<!-- Customize your theme here. -->
</style>
<style name="AppParent" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
在emulator中运行时,我的布局如何从
style.xml
中获取样式,即使在任何地方都没有提到它?如果我想引用布局中的其他样式,该怎么办?样式在Android清单中定义为应用程序和活动节点的属性
请检查AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
应用程序的基本主题在Manifest.xml中定义:
<application
android:name=".YourApp"
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"> <!--This line-->
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
<style name="ACustomStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>
</resources>
您的布局XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout"
style="@style/ACustomStyle">
问题1:您的布局如何选择style.xml
答:-这是由androidmanifest.xml文件完成的,我将向您展示一个使用我的androidmanifest文件的示例
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
查看您的AndroidManifest.xml
文件。android:theme
在application
和activity
中指定为属性。@Clive Seebregts:hah!太好了……谢谢。@subham:解释得很好。如果我想在第二项活动中添加单独的风格,那么这就是方法吗?但我在mainfest中的内容将应用于所有活动?是的,我实际上已经指出,您的默认androidmanifest样式将应用于每个活动,但是如果您想将单独的样式应用于第二个(另一个)活动,那么我已经通过使用以下内容展示了一种单独活动的方式:-
<style name="CustomFontStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#00FF00</item>/>
</style>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_id"
style="@style/CustomFontStyle" ///these is that line for your ///custome style
android:text="@string/hello_world" />
</LinearLayout>
<resources>
...
<style name="MyCustomTheme" parent="android:style/Theme">
<item name="android:textColorPrimary">#ffff0000</item>
</style>
...
</resources>
<activity
android:name="com.myapp.MyActivity"
...
android:theme="@style/MyCustomTheme"
/>