2017-04-08 12 views
1

こんにちは。この質問があります:ツールバー内にロゴ画像を追加するには

1)イメージを追加するにはどうすればいいですか?

イメージロゴのサイズはW×Hですか?ここで

ツールバー

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"  
xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent">  
    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto"   
    android:id="@+id/toolbar"   
    android:layout_height="wrap_content"   
    android:minHeight="?attr/actionBarSize"   
    android:background="?attr/colorPrimary"   
    android:layout_width="match_parent" /> 

おかげ

----更新:解決

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"   
    android:id="@+id/toolbar"   
    android:layout_height="wrap_content"   
    android:minHeight="?attr/actionBarSize"   
    android:background="?attr/colorPrimary"   
    android:layout_width="match_parent" /> 

<ImageView  
android:id="@+id/toolbarimage"  
android:layout_marginTop="12dp"  
android:layout_marginBottom="6dp"  
android:layout_width="wrap_content"  
android:layout_height="wrap_content"  
android:layout_gravity="center"  
android:src="@drawable/Logo" /> 
</android.support.v7.widget.Toolbar> 

enter image description here

答えて

1

はどのようにツールバー内の画像のロゴを追加します?

まず、カスタムツールバーを作成する必要があります。Replacing the Action Barに従うと、カスタムツールバーを作成できます。

その後、単にあなたのツールバーのレイアウトの内側の任意の要素を追加することができます

Toolbar.axml(Resources/drawableフォルダ内house.png):

<Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/actionBarSize" 
    android:background="?android:attr/colorPrimary" 
    android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/house" /> 
</Toolbar> 

MainActivity.cs:

[Activity(Label = "ToolbarDemo", MainLauncher = true, Icon = "@drawable/icon")] 
public class MainActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView (Resource.Layout.Main); 

     var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar); 
     SetActionBar(toolbar); 
     ActionBar.Title = ""; 
    } 
} 

をそして次のようなものが得られます: enter image description here

イメージロゴサイズはどのくらいですか?

android:layout_widthandroid:layout_heightImageViewの大きさを決定するが、デフォルトで、画像がImageViewによって自分自身を調整しないであろう。あなたはandroid:adjustViewBounds="true"を設定することにより、この動作を変更することができます

<Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/actionBarSize" 
    android:background="?android:attr/colorPrimary" 
    android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"> 
    <ImageView 
     android:layout_width="120dp" 
     android:layout_height="120dp" 
     android:adjustViewBounds="true" 
     android:src="@drawable/house" /> 
</Toolbar> 

Androidのレイアウトの詳細については、Android Layout Documentのレイアウトパラメータのセクションを参照してください。

+0

本当にあなたの解決策を見てうれしいです。私はV7 appCompatのインストールに問題があるので、私を助けてください。ここで私のステップ、私はプロジェクトの下のコンポーネントを右クリックしてV7 AppCompatを取得します。まず、Xamarin.Android.Support.compatとその他のXamarin.Android.Support ... rを持つすべてのDLLがComponentフォルダとReferenceフォルダにインポートされます。しばらくすると、参照フォルダにあるXamarin.Android.Supportで始まるすべてのDLLに黄色い三角形の警告記号が付いていますか?これはどういう意味ですか?参照フォルダを右クリックしてNuget Managerを選択すると、V7 AppCompatがインストールされていることが表示されます。何が起こっている? – MilkBottle

+0

一部の依存関係が完全にインストールされていない可能性があります。すべてのnugetパッケージをアンインストールし、 'xamarin.android.support.v7.appcompat'を再度インストールしてください。 –

+0

first get support v7コンポーネント経由でAppcompatします。参照フォルダをクリックするとv7 Appcompatが表示されます:1)インストール済み25.1.1 - アンインストールbtn
2.バージョン25.1.0 - アップデートbtn
アップデートbtnをクリックして25.1を取得する必要があります。0でない場合は、黄色の三角形の警告サインが表示されます。 25.1.1に問題がありますか?バージョン25.1.0を使用する必要がありますか?ありがとう – MilkBottle

関連する問題