2016-02-16から1日間の記事一覧
ボタンやレイアウトなどのビューのBackgroundを色で指定し、その色を後から動的に取得する方法です。 View v = target; // 対象のビューです。 ColorDrawable colorDrawable = (ColorDrawable) v.getBackground(); int colorInt = colorDrawable.getColor();…
静的に組み込んだフラグメントをタグで探す方法です。 レイアウトリソースの当該フラグメントに、任意のタグを付けます。 識別にオブジェクトも使うことができますが、参照を取得するだけならテキストをキーのように指定するのが簡単です。 <fragment android:tag="key" android:layout_width="match_parent" android:layout_height="wrap_content" android:name="package" android:id="@+id/myfragment" /> アクティビティ</fragment>…
事前準備 1.スナックバーを使用するためにサポートライブラリーを、SDKマネージャーを使ってダウンロードします。2.Project Structure の Dependenciesタブから com.android.support:support-v4:23.1.1 をライブラリーに追加します。 3.build.gradleに以下の…