Android Studio Allow User to Upload Their Own Background Image
Resources Director is a tool window for importing, creating, managing, and using resources in your app. You can open up the tool window by selecting View > Tool Windows > Resources Manager from the carte bar or by selecting Resources Managing director on the left side bar.
Effigy 1: The Resource Manager
- Click Add together
to add a new resource to your project. Yous can add image avails, vector assets, fonts, resources files and values, or yous tin import resources into your projection. - The module dropdown lets you view resource specific to a module.
- Utilize the search bar to search for a resource across all modules in your project.
- The Resource Manager groups your resources by type. Utilize these tabs to switch betwixt each resource type. Click the overflow icon
to testify boosted resource types. - The filter button lets you lot view resource from local dependent modules, external libraries, and the Android framework. Yous can also apply the filter to bear witness theme attributes.
- The main content area displays previews of your resources. Correct-click on a resource to see a context carte du jour where, among other things, you lot can rename the resources and search your app for where the resources is used.
- Click these buttons to view your resource as either tiles or lists.
- Click these buttons to change the preview size of your resource.
In improver to the features mentioned higher up, the Resource Managing director provides a simple way to bulk import drawables into your project. You lot can drag and drop your image files—including SVG files—directly onto the Resources Manager, or y'all can utilize the Import Drawables wizard. For more information, see the Import resource into your project section below.
Double-click on a resource to have the Resource Manager display more detailed information. If you have multiple versions of a resource, this detailed view displays each version forth with whatsoever associated qualifiers, as shown in figure 2. From here, y'all tin can also double-click on a specific version to open it in an editor window.
Figure ii: The Resource Manager showing versions of an image resource for different screen densities.
Import drawables into your project
You lot can import epitome resource past dragging and dropping the resource files or folders directly onto the Resource Manager. Later you drop the resources onto the Resources Manager, the Import drawables dialog appears, where you tin view the summary of the resources and add together any needed qualifiers before importing.
To import prototype resource into your project, exercise the following:
-
Drag and drop your images directly onto the Resource Managing director window in Android Studio. Alternatively, yous can click the plus icon (+), choose Import Drawables, as shown in figure iii, so select the files and folders that yous want to import.
Figure iii: Select Import Drawables from the dropdown carte du jour.
-
The Import drawables dialog appears. As shown in effigy iv, this dialog displays a listing of the resources you're importing. You can rename resource by clicking on the textbox above each resource preview.
If yous're providing multiple versions of the same resource, be sure to add device configuration qualifiers that describe the specific configuration that the resources supports. For example, if you're providing multiple versions of the same resource for unlike screen densities, you tin add together a Density qualifier for each version. Note that if two or more resource have the same proper name and qualifiers, only one version is imported. For more information on resources qualifiers, run across Providing alternative resources.
Effigy iv: The Import Drawables dialog.
Once yous've named your resource and added any necessary qualifiers, click Next.
-
The next screen shows a summary of the resources y'all're importing. When y'all're ready to import, click Import.
In the Resources Manager window, your resources are now ready for y'all to use in your project, as shown in figure 5.
Figure 5: The Resource Manager now shows your imported images.
Automatically parse drawable densities
When y'all import a file or folder, and its path contains a density qualifier, the Resources Manager automatically applies the density qualifier as function of the import. The Resource Manager tin parse both Android's density qualifiers and iOS's scale factors.
This table lists how different supported densities is represented for both Android and iOS:
| Density | Android density qualifier | iOS scaling factor |
|---|---|---|
| Low-density (~120dpi) | ldpi | non supported |
| Medium-density (~160dpi) | mdpi | original scale |
| Loftier-density (~240dpi) | hdpi | not supported |
| Actress-high-density (~320dpi) | xhdpi | @2x |
| Actress-extra-high-density (~480dpi) | xxhdpi | @3x |
| Actress-extra-extra-high-density (~640dpi) | xxxhdpi | @4x |
Hither are some examples of how input paths translate to resource paths after import:
- Android density qualifier: hdpi
- Input path: /UserFolder/icon1/ hdpi /icon.png
Resources path: <projectFolder>/<moduleFolder>/src/chief/res/ drawable-hdpi /icon.png - Android density qualifier: xxhdpi
- Input path: /UserFolder/icon1/abc- xxhdpi /icon.png
Resource path: <projectFolder>/<moduleFolder>/src/main/res/ drawable-xxhdpi /icon.png - iOS scaling cistron: @2x
- Input path: /UserFolder/icon1/icon @2x .png
Resource path: <projectFolder>/<moduleFolder>/src/master/res/ drawable-xhdpi /icon.png - iOS scaling factor: @2x
- Input path: /UserFolder/icon1/icon @2x _alternate.png
Resource path: <projectFolder>/<moduleFolder>/src/main/res/ drawable-xhdpi /icon_alternate.png
For more than information on supporting devices with different pixel densities, see Back up different pixel densities.
Elevate and drop drawables into your layout
Y'all can drag and driblet drawables from the Resource Director straight onto a layout. When you drop a resource onto a layout, the Resource Manager creates a corresponding ImageView for that drawable, every bit shown in blitheness one:
Animation 1: Dragging and dropping drawables onto a layout in Design view.
You can besides elevate and drop directly onto the XML of the layout, equally shown in blitheness 2:
Animation 2: Dragging and dropping drawables onto a layout in Text view.
When dropping a drawable onto a layout in the Text tab, the generated code differs depending on where you drop the layout:
- If yous drop a drawable onto a bare area, the Resource Manager generates a respective
ImageView. - If you drop a drawable onto any attribute in the layout XML, the Resources Manager replaces that aspect value with a reference to the drawable. Note that you lot can as well drag whatever other resources type onto an XML attribute to supersede the attribute value.
- If y'all drop a drawable onto an existing
ImageViewelement, the Resource Managing director replaces the corresponding source attribute.
Source: https://developer.android.com/studio/write/resource-manager
0 Response to "Android Studio Allow User to Upload Their Own Background Image"
Postar um comentário