ProgressBar dialog Without Border

2019-02-20 15:57发布

I am displaying a ProgressBar in Android, as seen below:

alt text

but there is a white border around the progress bar. What if I dont want to display any border?

i.e., only the progress bar circle and text should be shown in the progress bar dialog.

How do I display the progress bar as shown below? (How do I display a progress dialog as Searching in the below image:)

alt text

Update: I failed to find a solution for this, but I think there should be some trick to display a progress bar dialog in this way. I mean to say there should be a way by extending some styles in styles.xml. Please anybody focus on this question and help me to display such dialog.

2条回答
叼着烟拽天下
2楼-- · 2019-02-20 16:51

After some experiments I got to the following:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="my_style" parent="@android:style/Theme.Dialog" >
        <item name="android:windowBackground">@null</item>
    </style>
</resources>

If I use this theme as a style for an Activity I get no frame. If you use this with the Dialog constructor: Dialog(context, theme) you get no frame.

查看更多
放我归山
3楼-- · 2019-02-20 17:04

do you still need ideas for this? I implemented the same thing in my app, but not as a dialog, I had two layouts that overlap each other. I then flip between the two layouts by setting the visibility .setVisibility(). As for the actual progress bar itself, I use this:

EDIT: Here's my whole XML file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/background"> 
     <RelativeLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:id="@+id/search_header" android:background="@drawable/header">
           <!-- Some things I need for the header (title, etc) -->
     </RelativeLayout>  
    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:id="@+id/spinner_layout" android:layout_below="@+id/search_header" 
     android:layout_centerHorizontal="true" android:layout_centerVertical="true">
     <ProgressBar android:id="@+id/title_progress_bar"
   style="?android:attr/progressBarStyleSmallTitle"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true"
   android:layout_centerVertical="true"
   android:visibility="visible"
   android:indeterminateOnly="true"/>
  <TextView android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:id="@+id/loading_label" android:text="Loading..." 
   android:layout_gravity="center_vertical" android:layout_marginLeft="5dip">
  </TextView>
 </LinearLayout>
 <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" 
  android:layout_below="@+id/search_header" android:id="@+id/list_contents">
  <!-- Stuff you want to show after returning from the AsyncTask -->
 </RelativeLayout>    
</RelativeLayout>

I use this layout for an Activity with an AsyncTask, so onPreExecute(), I do something like:

@Override
protected void onPreExecute(){
 findViewById(R.id.list_contents).setVisibility(View.GONE);
 findViewById(R.id.spinner_layout).setVisibility(View.VISIBLE);
}

And then do whatever I have to do, and onPostExecute() I have:

@Override
protected void onPostExecute(Cursor cursor){
 findViewById(R.id.list_contents).setVisibility(View.VISIBLE);
 findViewById(R.id.spinner_layout).setVisibility(View.GONE);
}
查看更多
登录 后发表回答