简体   繁体   English

Android和Java:无法对我的App主题和App图标进行任何修改

[英]Android & Java: Can't do any modifications with my App theme & App icon

as I'm very new to Android programming, this may be a simple question, but I was googling for an answer for hours now and all results did not work for me. 由于我是Android编程的新手,所以这可能是一个简单的问题,但是我已经搜寻了好几个小时的答案,而所有结果对我来说都不起作用。

I'm using Android studio and I'd like to have an application Icon on the top left corner in my action bar. 我正在使用Android Studio,我想在操作栏中的左上角有一个应用程序图标。

I created a new project with a blank activity using Android V. 4.1 (API 16) as minSDK and API 21 as targetSDK. 我使用Android V.4.1(API 16)作为minSDK和API 21作为targetSDK创建了一个空白活动的新项目。

When I compile & run the new project on my mobile device (Android V 4.3, Samsung G S3), I get the blank activity with an action bar that contains the activity title. 当我在移动设备(Android V 4.3,Samsung G S3​​)上编译并运行新项目时,我得到了带有活动栏的空白活动,其中包含活动标题。

The tutorials on android's website always show an action bar that displays the app icon on the left side of the activity title, but it isn't displayed on my screen.. android网站上的教程始终会显示一个动作栏,该动作栏在活动标题的左侧显示应用程序图标,但它不会显示在我的屏幕上。

I googled for it and found solutions to "enable" the home icon in my MainActivity class (extends ActionBarActivity): 我用它搜索了一下,找到了在MainActivity类中“启用”主页图标的解决方案(扩展了ActionBarActivity):

getActionBar().setIcon(R.id.launcher);
getActionBar().setLogo(R.id.launcher);
getActionBar().setDisplayShowHomeEnabled(true);

Every of these three tries resulted in an error on my mobile device "application stopped".. 这三个尝试中的每一个都导致我的移动设备“应用程序已停止”错误。

Then, I read that newer themes don't display the icon anymore. 然后,我读到新主题不再显示图标。 Is that correct? 那是对的吗? Well, I don't know if it is correct, but I even can't change my theme. 好吧,我不知道它是否正确,但是我什至无法更改主题。 Right now, by default, the app uses the Theme.AppCompat.Light.DarkActionBar . 现在,默认情况下,该应用程序使用Theme.AppCompat.Light.DarkActionBar My problem is, that I can't change it to some other theme like Theme.Holo or Theme.Material , I always get errors on my mobile device or Android Studio simply doesn't accept the theme. 我的问题是,我无法将其更改为其他主题,例如Theme.HoloTheme.Material ,我总是在移动设备上出现错误,或者Android Studio根本不接受该主题。

Well, does anybody know what I'm doing wrong? 好吧,有人知道我在做什么错吗? I also tried to inherit my MainActivity from Activity instead of ActionBarActivity , but the result was always the same... 我还尝试从Activity继承我的MainActivity ,而不是从ActionBarActivity继承,但是结果始终是相同的...

Officially the support for showing App Icon or Logo in the ActionBar has been removed as per The Material Design Guidelines 根据《 材料设计指南》,正式删除了在ActionBar显示App图标或徽标的支持。

You can't use Icon or any Logo especially if your using AppCompat library 您不能使用图标或任何徽标,尤其是在使用AppCompat library

You should reference drawables in your application by R.drawable . 您应该在应用程序中通过R.drawable引用可绘制R.drawable R.id is normally used for the id of a View. R.id通常用于View的ID。 Try to replace setIcon(R.id.launcher) with setIcon(R.drawable.launcher) . 尝试将setIcon(R.id.launcher)替换为setIcon(R.drawable.launcher)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM