带有四个图标的工具栏如何设置如此图像?
我想在工具栏中设置四个图标,如图像。
我有制作工具栏。 &安培;在menu_main.xml中设置图标。但我没有得到。为什么任何人都可以帮助我为什么不来?
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
toolbar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@android:color/white"
android:background="#f26925"
>
</android.support.v7.widget.Toolbar>
<!--<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mumbai"
android:textColor="@android:color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_gravity="left"
/>-->
<!-- Layout for content is here. This can be a RelativeLayout -->
</LinearLayout>
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/bookmark"
android:icon="@drawable/bookmark"
app:showAsAction="ifRoom"
android:title="Compose">
</item>
<item
android:id="@+id/search"
android:icon="@drawable/search"
app:showAsAction="ifRoom|withText"
android:title="Profile">
</item>
<item
android:id="@+id/loc"
android:icon="@drawable/loc"
app:showAsAction="ifRoom|withText"
android:title="Profile">
</item>
<item
android:id="@+id/menu"
android:icon="@drawable/menu"
app:showAsAction="ifRoom|withText"
android:title="Profile">
</item>
</menu>
使用此功能后,我无法在工具栏中显示图标。没有图标出现的原因?
答案 0 :(得分:0)
Please add menu inflating code inside your Activity
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
答案 1 :(得分:0)
使用工具栏的自定义视图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="left">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upgrade"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:paddingRight="7dp"
android:paddingLeft="5dp"
android:textSize="11dp"
android:textColor="#c23c3c"
android:textAllCaps="false"
android:drawableLeft="@drawable/upgrade"
android:drawablePadding="5dp"
android:background="@drawable/upgrade_button_round"
android:id="@+id/button" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/noticication_icn"
android:layout_alignParentRight="true"
android:id="@+id/notificationID"/>
<TextView
android:id="@+id/notificationsCount"
android:layout_marginTop="5dp"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentRight="true"
android:textSize="10sp"
android:textAlignment="center"
android:background="@drawable/textviewcircle"
android:textColor="@color/white"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ppp_icn" />
</RelativeLayout>
actionbar_customview.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/projectCoordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
MainActivity.xml
#!/usr/bin/perl -w
use strict;
use lib qw("/path/to/module/");
use Net::SSH::Perl;
my $host = "hostname";
my $user = "username";
my $password = "password";
my $command = 'dir /var/log/'; #your command to read the directory
my $ssh = Net::SSH::Perl->new("$host", debug=>0);
$ssh->login("$user","$password");
my ($stdout,$stderr,$exit) = $ssh->cmd("$command"); #the standard outputs will be fetched
print $stdout; #obviously the STDOUT will be printed