implement UP button by default (UP button icon) - android

i know that if i want to implement UP button on the up-left-corner of the screen (i mean just its icon, not its whole implementation) i have to put getActionBar().setDisplayHomeAsUpEnabled(true) in the onCreate()method of desired activity
but i want to know is it possible to appear UP button icon in its place without using getActionBar().setDisplayHomeAsUpEnabled(true)???
because in android studio i've done nothing but this icon is appeared

You can provide Up Navigation using one of these two methods:
1- Specify the Parent Activity
Note that android:parentActivityName is added on Android 4.1 (API level 16). So if your app supports Android 4.0 and lower, include the Support Library with your app and add a element inside the . Then specify the parent activity as the value for android.support.PARENT_ACTIVITY, matching the android:parentActivityName attribute.
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
2- Add Up Action
#Override
public void onCreate(Bundle savedInstanceState) {
...
getActionBar().setDisplayHomeAsUpEnabled(true);
}
To have more info on this, check this link from the docs. http://developer.android.com/training/implementing-navigation/ancestral.html

Related

Dynamic colors API is not working on Android sdk 32

I have a simple android app which I would like implement dynamic color from material 3. I use Google guideline (https://codelabs.developers.google.com/codelabs/apply-dynamic-color#0) (I override onCreate() in Application class and I add this class in android manifest), and dynamic color is working on emulator (sdk 31/32/33), however on physical device is not work (sdk 32). And if I to add colors-v31 in project and override color, it's work on phone. What could be the problem? Do I understand correctly that it is not necessary to override color resources for dynamic colors?
Application.kt
class Application: Application() {
override fun onCreate() {
super.onCreate()
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
AndroidManifest.xml
<application
android:name=".Application"
<activity>
android:exported="true"
</activity>
<!-- others xmls tags -->
</appication>
In themes.xml I use parent Theme.Material3.DayNight.NoActionBar and colors from material theme builder
Screenshots of how it's now and how it should be: color is pink, but application is green (default color for this app)
green app
and how app should be: if color system is orange
and app is orange
if i override colors in v-31 it work. but i was read android devs codelabs and i think it is not necessary to override colors
These palettes are specific to Android 12 (API 31) so you will need to place relevant files in folders with a -v31 suffix unless your app has a minimum SDK set to 31 or higher.
Also in your AndroidManifest.xml file specify an explicit value for android:exported for the activity.
<application>
<activity android:name=".MainActivity"
android:exported="true">
<!-- others xmls tags -->
</application>

How to change the app name which is placed in the launcher screen

i want to change the app name. Not every where. only in the launcher screen of an android.
Not inside the app or in the installation screen.
is this possible?
Your Manifest.xml file should be similar to this:
<application
....
<activity
android:name=".activities.SplashScreenActivity"
android:label="myLabel"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
....
....
As you can see every Activity node has a label attribute. Changing this changes only the activity label (not all over the application)
Set the android:label attribute of the main Activity in your Android Manifest (the one that starts when the Launcher icon is pressed)

Setting the theme in an android application

I've gone through quite a bit and I'm still at a loss for what I need to do:
http://developer.android.com/design/style/themes.html
http://developer.android.com/guide/topics/ui/themes.html
I have the view set to use the "Dialog" theme in my IDE (IntelliJ IDEA 14.1.2) and the application looks like this in the insepctor:
However looks completely different on my phone (Much larger resolution, but that's not the point).
What am I doing wrong and how can I get this effect?
i use this in one of my activities and it is ok:
<activity
android:name="eddine.charef.mechalikh.swipedemo.mapDialog"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:theme="#android:style/Theme.Dialog" ><!--add this-->
</activity>
maybe your android version doesn't support that.
Add to the Android Manifest
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>

Back from launcher icon in ActionBar

I am creating ActionBar using android-support-v7-appcompat. In action bar I have up navigation from logo enabled and its working fine on device with API level 17. But when I run my app on API level 10 device its not working. Please help me. Thanks in advance.
Using following code in activity-
private ActionBar ab;
ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
In Manifest file-
<activity
android:name=".History"
android:screenOrientation="portrait"
android:theme="#style/Theme.Styled"
android:parentActivityName=".MainActivity">
ActionBar is not supported for below API 11 level.Thats why you are getting error.Read this documentation.
To make your code work in lower version, you have to use android-support-v7-appcompat instead of ActionBar.Read the below blog about how to migrate from ActionBar to android-support-v7-appcompat.
http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html
EDIT :
you can download and setup the support library as mentioned here
Below is my explanation based on your updated code,
-To enable up navigation in beginning in Android 4.1 (API level 16),
you can declare the logical parent of each activity by specifying the android:parentActivityName attribute in the element.
-If your app supports Android 4.0 and lower, include the Support Library with your app and add a <meta-data> element inside the . Then specify the parent activity as the value for android.support.PARENT_ACTIVITY, matching the android:parentActivityName
attribute like below example,
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
For more info read
http://developer.android.com/training/implementing-navigation/ancestral.html
Hope it helps you.

Feature Custom Title: Cannot combine custom titles on API 11 and above

I have a project in which i setted:
minSdkversion setted to 10
MainActivity is a TabActivity
Code in onCreate method is this:
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
...
With previous settings, all works well! But, if i set minSdkVersion to 11 or above, this exception occurs:
android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
I don't understand why happens this just changing minSdkVersion.
I red a lot about this problem on this site. I tried setting:
Theme.NoTitleBar in main layout and after in Manifest file too
I put those 3 lines in all possible positions
If i comment first line a NullPointerException occurs when i call something on my TextView reference of my CustomTitle layout
I tried setting, in theme.xml file declaration, "windowNoTitle" = true
Since i'm using functions available from API 11 only, i want to set minSdk to 11 before loading App on Store. How can i do ?? I need Help
Edit: With minSdkVersion = 10 and Theme.NoTitleBar in Manifest, same error occurs. Removing it, all works as before.
Can anyone provide a working code (manifest and activity code) for setting a custom title when API is 11 or above ? Thx much
Fixed by my self. I don't know why, but simply adding in manifest file "theme" property for each activity's declaration, all works:
From this:
<activity
android:name=".CheckActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
</activity>
To this:
<activity
android:name=".CheckActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme" >
</activity>
#kinghomer I have tried CUSTOM_TITLE its on 2.2 (API 8) actually. Let me try on API 11 and get back to you!
Before that, you need not make Theme.NoTitleBar anywhere, can be controlled in .java file directly. Give me some time, will be back!
res/values-v11 defalut use this code :
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
change "android:Theme.Holo.Light" to "#android:style/Theme" will be ok!
tips: if your project no have "res/values-v11", then check your project referenced "lib project" 。
Other than the accepted answer ,there is another way to solve this :
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme" >
assign a theme attribution to application in the xml-based mainifest,that should work for all activities.
This problem occurs when you try to add a custom title bar along with extending your activity by ActionBarActivity or AppcomActivity. These two activity classes already have title bar defined.
So, when you try to add your own custom title bar a conflict arises, which title bar to use - your custom one or the one provided by activity extended.
To solve this issue, just extend your activity by Activity which does not have any predefined title bars, so yours will be accepted without any conflict.
public void MyActivy extends Activity
{
// your code
}
I just added android:theme="#android:style/Theme" in activity in AndroidManifest.xml file and it worked super fine.
<activity
android:name=".MainActivity"
android:theme="#android:style/Theme" >
</activity>
Hope this works for you as well.
In your AndroidManifest file, use this snippet instead of yours.
From this:
android:theme="#style/AppTheme">
to this:
android:theme="#style/custom_title">

Categories

Resources