【发布时间】:2015-04-06 00:33:00
【问题描述】:
我敢肯定,我会因为缺乏特异性或提出已被问到的问题而感到悲伤,但这确实是最后的选择,我真的尝试了太多方法来解释它们。这是我的问题:
我一直在学习developers.android.com 提供的标准教程,并且几乎没有问题地完成了ActionBar 的样式设置。好吧,现在我正在为那些缺乏问题买单,我真的无法在操作栏上使用任何类型的自定义主题。
事实:
- 我正在使用 AppCompat-V7,因为我的应用非常简单,并且可以与尽可能多的版本完美兼容。
- 我可以更改基本主题(Dark、Light 和 Light.DarkActionBar)
- 我尝试了 Android 操作栏样式生成器,并在此处遵循此教程 (http://www.androiduipatterns.com/2012/09/creating-custom-android-styles-easy-way.html)
- 我观看了一些与我的问题/设置有些相关的视频,以尝试解决问题。
- 我尝试了各种方法(全都错了)来让它工作,其中一些可能甚至没有意义。
那么……怎么样?
以下是我认为相关的文件,但如果有人想查看更多内容,请随时提问。考虑到我几乎没有通过 Android 教程,我没有太多可看的内容,所以我想这很好。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="godwin.com.study" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
<activity
android:name=".MainActivity"
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=".DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="godwin.com.study.MainActivity" />
</activity>
</application>
</manifest>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_background</item>
</style>
</resources>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "godwin.com.study"
minSdkVersion 8
targetSdkVersion 18
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:18.0+"
compile fileTree(dir: 'libs', include: ['*.jar'])
}
随时提出问题,但要为“我不知道”做好准备。我几乎迷路了。是的,我确实删除了很多我的尝试。它们重叠并相互干扰,所以我在文件中的内容确实有效,除了以下行:
<item name="background">@drawable/actionbar_background</item>
在 themes.xml 文件中。我已将“actionbar_background.png”文件放入“drawable”文件夹,但它仍然只生成“...Light.DarkActionBar”主题。
我真的希望这很简单,但是通过我所有的搜索,我还没有找到答案。
附带说明:这是我第一次开发 Android 应用程序,或者至少尝试过,我真的不认为 Android 在他们的教程方面做得很好。我的意思是,我很擅长编程。主要使用 C++,但也使用一些 Java、Javascript 和网页设计语言,我大部分时间都在使用它们。只有我吗?还是进入应用开发世界真的很困难?
编辑:简单地说,我尝试了很多方法来更改具有自定义主题的操作栏的外观(无论是使用颜色代码还是图像/.pngs),但我能得到它的唯一方法通过使用预设主题(Light、Dark 和 Light.DarkActionBar)进行更改。
【问题讨论】:
-
“我真的无法在操作栏上使用任何类型的自定义主题”——嗯,你有机会解释一下你的意思吗?只是背景吗?如果是,您是否有理由不使用色调系统(例如,
colorPrimary)? -
我希望能够使用我提到的 Android 操作栏样式生成器之类的东西,所以这将是一个更改操作栏的自定义主题(对吗?)我也尝试使用我的拥有我所说的“actionbar_background”.png 并链接到它(看看我是否可以更改/自定义操作栏的任何部分(进度就是进度,我很高兴暂时能够至少做到这一点)。我做到了尝试将颜色更改为#ff0000,但我忘记了我使用的方法。无论哪种方式,它都不起作用。理想情况下,我想控制操作栏,但我还没有做到这一点。跨度>
标签: android android-actionbar styles themes android-appcompat