我知道你可以将图标图像添加到应用程序栏,但是我想知道是否有方法在Android上的应用程序栏中放置较大的徽标图像。附件中的图片将其放在应用程序栏后面,但我试图在应用程序栏中找到它。这可能吗?如何在Android应用程序栏中添加徽标图像?
回答
至于你的形象是大,长方形,你可以将它设置在你的动作条的背景:
final ActionBar actionBar = getActionBar();
BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.raw.actionbar_background));
actionBar.setBackgroundDrawable(background);
为此,您可以创建一个activity
说“BaseActivity”和onCreate
添加片段方法,并在您想要显示您的更改的所有活动中扩展该活动 或者您可以将不同的方形徽标设置为应用图标并将其设置为您的操作栏图标。
public BaseActivity extends Activity{
@override
public void onCreate(Bundle bundle){
/// add snippet
}
}
yourActivity/yourActivities extends BaseActivity
这段代码在哪里?每个活动的java文件? – Casey
看到我更新的答案@Casey – KDeogharkar
1)使用最新的Android工具栏
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Place your ImageView and Image-->
<!-- mention image size-->
</android.support.v7.widget.Toolbar>
示例代码:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:id="@+id/back_menu_ll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_logo"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@color/title_first_textcolor"
android:textSize="@dimen/abc_text_size_title_material"
android:gravity="left"
/>
</android.support.v7.widget.Toolbar>
2)您可以通过编程设置标志:
Toolbar tool_bar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(tool_bar);
tool_bar.setLogo(R.drawable.image);
有关工具栏的详细信息,检查这个链接: http://developer.android.com/reference/android/widget/Toolbar.html
此代码是否在app_bar_home_page.xml文件或其他位置?我得到一个错误:错误解析XML:在这一行不匹配的标记“” – Casey
在Gradale文件中添加Appcompat Libary –
有关最新API的XML应该是内部的,
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
活动是应该的,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setLogo(R.drawable.ic_call_black_24dp);
setSupportActionBar(toolbar);
}
试过这个,并得到一个错误:java.lang.RuntimeException:无法启动活动ComponentInfo {edu.csusb.ossmassistant/edu.csusb.ossmassistant.home_page}:java.lang.IllegalStateException:已附加 – Casey
- 1. Android - 如何在行动栏中显示应用程序徽标
- 2. 如何将图标(图像,徽标..)添加到状态栏
- 3. 在android的应用程序图标上添加通知徽章
- 4. 如何在Android中的视频中添加应用徽标
- 5. 如何指导图像添加到应用程序在Android中
- 6. 如何在Android应用程序中添加图标?
- 7. 如何将徽标添加到Twitter引导程序导航栏?
- 8. 如何在此引导程序片段中添加徽标图像
- 9. 如何在Android应用程序的开始屏幕上添加徽标?
- 10. 在导航栏中间添加徽标?
- 11. 跨应用程序在全球范围内添加徽标图像
- 12. 在scrolldown添加过渡到居中的导航栏图标/徽标/图像
- 13. 有没有办法将徽章添加到Android中的应用程序图标?
- 14. 如何在工具栏上添加徽章MenuItem图标
- 15. 如何在ipad中的标签栏应用程序中添加拆分视图
- 16. 在Android手机应用程序图标中显示徽章
- 17. 在Android中显示应用程序图标的徽章数
- 18. 如何在JFrame的标题栏中添加图像图标?
- 19. 是否有可能在android中添加应用程序图标状态栏?
- 20. Android:为我的应用程序内部的图标添加徽章
- 21. 如何在windows phone应用程序栏中添加四个以上的图标?
- 22. 在Bootstrap导航栏前添加徽标
- 23. 如何在android中以编程方式添加标题栏背景图像
- 24. iPhone应用程序中的应用程序图标徽章
- 25. 如何使操作栏上的非可点击的应用程序图标像android应用程序中的android
- 26. 如何从java代码添加图像到Android应用程序
- 27. 如何在Bootstrap导航栏中添加多个徽标?
- 28. 徽标图像居中&菜单栏下面徽标
- 29. 如何在安装Android应用程序时将图标添加为图标
- 30. 如何在rmarkdown的导航栏标题栏中添加自定义徽标?
http://stackoverflow.com/ a/16029214/2826147 –