Android 我怎样才能进入可牵引设备?
我有一个这样的布局(用于片段):Android 我怎样才能进入可牵引设备?,android,android-layout,android-fragments,xamarin,Android,Android Layout,Android Fragments,Xamarin,我有一个这样的布局(用于片段): 我将此形状作为上述布局中文本视图的背景: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ffffff" /> <stroke android:width="1dip" android:color="#
我将此形状作为上述布局中文本视图的背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
我需要改变可拉丝的颜色。如何从代码中访问它
我基本上有许多片段的实例显示,我需要从特定片段访问背景绘图。您可以这样做:
View v = findViewById(R.id.Text_Value);
ShapeDrawable d = (ShapeDrawable) v.getBackground();
或者,如果您有对特定片段的引用:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/Text_Value"
android:text="0"
android:textSize="32dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/PlaySquareShape"/>
</RelativeLayout>
View v = frag.getView().findViewById(R.id.Text_Value);
您可以这样做:
View v = findViewById(R.id.Text_Value);
ShapeDrawable d = (ShapeDrawable) v.getBackground();
或者,如果您有对特定片段的引用:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/Text_Value"
android:text="0"
android:textSize="32dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/PlaySquareShape"/>
</RelativeLayout>
View v = frag.getView().findViewById(R.id.Text_Value);
您可以这样做:
View v = findViewById(R.id.Text_Value);
ShapeDrawable d = (ShapeDrawable) v.getBackground();
或者,如果您有对特定片段的引用:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/Text_Value"
android:text="0"
android:textSize="32dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/PlaySquareShape"/>
</RelativeLayout>
View v = frag.getView().findViewById(R.id.Text_Value);
您可以这样做:
View v = findViewById(R.id.Text_Value);
ShapeDrawable d = (ShapeDrawable) v.getBackground();
或者,如果您有对特定片段的引用:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/Text_Value"
android:text="0"
android:textSize="32dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/PlaySquareShape"/>
</RelativeLayout>
View v = frag.getView().findViewById(R.id.Text_Value);
完美的我试试看。谢谢:)这方面我还是新手。它奏效了!!唯一不同的是我的背景是一个GradientDrawable:)完美!我试试看。谢谢:)这方面我还是新手。它奏效了!!唯一不同的是我的背景是一个GradientDrawable:)完美!我试试看。谢谢:)这方面我还是新手。它奏效了!!唯一不同的是我的背景是一个GradientDrawable:)完美!我试试看。谢谢:)这方面我还是新手。它奏效了!!唯一的区别是我的背景是GradientDrawable:)