2017-12-29 32 views
0

私は特定のレイアウトのスクリーンショットを撮ろうとしていますが、問題はスクリーンショットにアクションバーが付いていて、上に青色のパッチがありますが、それでも問題は解決しませんが、ファブボタンで正常に動作しています。特定のレイアウトのスクリーンショットを撮る

私はXMLは私が欲しいもの

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.ragnar.useless.MainActivity" 

android:background="#ff4343" 
android:id="@+id/l1"> 

<ImageView 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:layout_width="180dp" 
    android:id="@+id/img" 
    android:layout_height="180dp" 
    android:src="@drawable/panda"/> 
<io.github.yavski.fabspeeddial.FabSpeedDial 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:gravity="bottom|end" 
app:fabGravity="bottom_end" 
app:fabMenu="@menu/main_menu" 
android:id="@+id/fabspeed" 
android:layout_alignParentBottom="true" 
android:layout_alignParentRight="true" 
app:miniFabDrawableTint="?attr/colorPrimaryDark" 
app:miniFabTitleTextColor="?attr/colorPrimaryDark" 
> 
</io.github.yavski.fabspeeddial.FabSpeedDial> 


</RelativeLayout> 

をコード -

    try { 

         actionBar.hide(); 
         String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "Hi" + ".jpg"; 
         fabSpeedDial.setVisibility(View.INVISIBLE); 
         // create bitmap screen capture 
         View v1 = getWindow().getDecorView().getRootView(); 
         v1.setDrawingCacheEnabled(true); 
         Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
         v1.setDrawingCacheEnabled(false); 

         File imageFile = new File(mPath); 

         FileOutputStream outputStream = new FileOutputStream(imageFile); 
         int quality = 100; 
         bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); 
         outputStream.flush(); 
         outputStream.close(); 
         fabSpeedDial.setVisibility(View.VISIBLE); 
         actionBar.show(); 
         return true; 


        } catch (Throwable e) { 

         e.printStackTrace(); 
        } 

below-コードを言及していますがアクションバーと上記bluepatchを取得せずRelativelayoutのスクリーンショットです。 提案や私もstackoverflowで似たような質問を見てきましたが、その答えを理解できなかったので、あなたが提供していることを説明してください。

答えて

0

これは問題です:

View v1 = getWindow().getDecorView().getRootView(); 

あなたはルートビューのスクリーンショットを取っています。 あなたはこのように、あなたの活動のレイアウトのルートでごRelativeLayout、上のIDを配置する必要があります。

android:id="@+id/myview" 

をそして私が言及した最初の行に置き換えます。あなたが取得します

View v1 = findViewById(R.id.myview); 

をレイアウトのビットマップ、アクションバーと上記の青色のバー(ステータスバーのバックグラウンド)がありません。 あなたのために働くかどうか教えてください!

関連する問題