2016-08-08 9 views
-1

(Canvas)クラスを表示するために私のアクションバーを追加するにはどうすればよいですか?ここでビューバーにアクションバーを追加するにはどうすればよいですか?

public class MainActivity extends AppCompatActivity { 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 


    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 


    //set paint color 

    setContentView(R.layout.activity_main); 
    //setContentView(new DrawView(this)); 


    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); 
    setSupportActionBar(toolbar); 
    //DrawView.setPaint(255, 235, 191, 47); 
} 

Here is my project.

私のプロジェクト で、ツール・バーはactivity_main.xmlに格納されます。私が何をしたいの

ビジュアル表現:私はsetContentView(R.layout.activity_main);を使用するときにP 左のスクリーンショットは、右が//setContentView(new DrawView(this)); enter image description here

みんなありがとうです、です!そのokがあなたの人を含むことができるならば。説明も?私はAndroidのプログラミングに新しいです:)ツールバーとビューのレイアウト・エディタ、およびボタンで

activity_mainのXML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.nikol.touchpaint.MainActivity"> 
<!-- <view 
     android:id="@+id/viewid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" />--> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     android:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

    <TextView 
     android:id="@+id/testText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="151dp" 
     android:text="Hello World!" /> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/button2" 
     android:layout_toStartOf="@+id/button2" 
     android:text="New Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginBottom="29dp" 
     android:layout_marginEnd="30dp" 
     android:text="New Button" /> 

</RelativeLayout> 
+1

なぜあなたが活動にキャンバスビューを置くことができないでくださいツールバー? –

+0

@ cricket_007このような意味ですか? http://puu.sh/qu73r/5df21ed733.png – Google0593

+0

正確ではありません...どうやってツールバーを手に入れますか? DrawViewを 'activity_main.xml'に追加することはできますが、Javaコード –

答えて

0

、あなたは「カスタムビュー」を参照してくださいどこにエディタでスクロールダウン。

ここから入力を開始できます。カスタムViewクラスを追加して、そのXMLに任意の場所に追加することができます。

custom view

0

あなたactivity_main.xmlは次のようになります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/contentView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.example.nikol.touchpaint.DrawView 
     android:id="@+id/drawView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

</RelativeLayout> 

は、あなたの活動に

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    DrawView drawView = findViewById(R.id.drawView); 
} 
関連する問題