I have researched this on Stack Overflow, but I didn't find the fix to my problem. I have a view that contains the code for a vertical, yellow line on the screen. I have an activity that creates the dialog whose content view is an instance of the view. The dialog pops up, but the yellow line doesn't show. What am I missing? Here is my code:
View :
public guidelines(Context context) {
super(context);
int x = this.getWidth()/2 - 3;
int y = this.getHeight();
shape = new ShapeDrawable(new RectShape());
shape.getPaint().setColor(Color.YELLOW);
shape.setBounds(x, 0, x+6, y);
}
@Override
protected void onDraw(Canvas canvas) {
shape.draw(canvas);
}
Layout for the View :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/---
android:layout_width="match_parent" android:layout_height="match_parent">
<!-- <--- android:background="#ccc"
android:layout_width="300dp" android:layout_height="300dp" android:paddingLeft="20dp"
android:paddingBottom="40dp" app:exampleDimension="24sp" app:exampleColor="#33b5e5"
app:exampleString="Hello, guidelines" /> -->
< ---
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/frame"/>
</FrameLayout>
Dialog Calling Code :
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
guidelines g = new guidelines(this);
dialog.setContentView(g);
dialog.show();
Thanks.
It was better to just use the drawRect
function of the canvas. I did that and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.