我有textview
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:drawableTop="@drawable/new" />
Run Code Online (Sandbox Code Playgroud)
我希望活动jave知道哪个图像已经设置drawableTop,如何?
Nim*_*ary 26
使用
Drawable[] drawables = textView.getCompoundDrawables();
Run Code Online (Sandbox Code Playgroud)
另外如果你想比较两个drawable.
Bitmap bitmap = ((BitmapDrawable)drawables[1] ).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)getResources().getDrawable(R.drawable.twt_hover)).getBitmap();
if(bitmap == bitmap2)
{
//Code blcok
}
Run Code Online (Sandbox Code Playgroud)
Jos*_*arl 10
首先,提供TextView一个ID,以便您可以在以下位置找到它Activity:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:drawableTop="@drawable/new" />
Run Code Online (Sandbox Code Playgroud)
其次,在您Activity找到TextView并onCreate在调用后获取方法中的复合drawable setContentView:
TextView textView = (TextView) findViewById(R.id.textView);
// Left, top, right, bottom drawables.
Drawable[] compoundDrawables = textView.getCompoundDrawables();
// This is the top drawable.
Drawable topCompoundDrawable = compoundDrawables[1];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12019 次 |
| 最近记录: |